Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't exist a relink button in compilers?

I work in Linux with c++, using eclipse. But i have worked with Visual Studio too. They haven't got (or at least I don´t know how to do it) a button to relink a project.

Example:

I have a big project (1), with hundreds of cpp. That project uses a small library (2) to do foo. If I change foo behavior, and compile it, generating a library, I need to clean the big proyect (1), re-compile, that links the external libraries (2) and works.

The problem is the big project doesn't change, but with hundreds of cpps, its compile time is about 5 min. 5 min is a small change in a second library.

Is possible to avoid this problem?

Thanks in advance

like image 334
vgonisanz Avatar asked Feb 19 '23 03:02

vgonisanz


2 Answers

I suspect, but it is just a guess, your project is missing a dependency between your foo library and other deliverables in your project.

In this way, when you modify foo, the compiler does not know that it needs to recompile (as much as required by the change in foo) the rest of the project, and this forces you to manually clean and rebuild.

Usually a dependency is specified in a highly compiler-specific way, maybe this other post from S.O can help you, or just google "eclipse c++ dependency management".

like image 193
sergio Avatar answered Feb 27 '23 08:02

sergio


You would generally use make with a makefile for this.

With this method, you can generate your own rules for building code, including bypassing compilation of lots of source files if you only thing needed is relinking.

For example, the makefile:

prog: main.o other.o makefile
    gcc -o prog main.o other.o

main.o: main.c makefile
    gcc -c -o main.o main.c

other.o: other.c makefile
    gcc -c -o other.o other.c

would not recompile main.c if the only file you changed was other.c. It would simply compile other.c to make other.o, then link other.o and main.o together to create prog.

That's generally how it's done in the "command line" world. It's likely that it's also how it's done behind the curtains in many IDEs as well, just hidden from you.

What you'll need to find out is why the dependency checking is not working as expected. Without further information on how your project is set up, it's a little hard to be definitive.

like image 44
paxdiablo Avatar answered Feb 27 '23 07:02

paxdiablo