ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello,
I have been using GCC to compile in linux but compiling large projects takes time because as far as I know the linking isnt incremental, is this correct?
Is there any way to build faster in linux?
ld does support incremental linking, but I wonder if that's actually the question you mean to ask. Are you using a Makefile? If not, you probably should be.
The link step usually doesn't take very long. If you're sure that it's the *link* that's taking a long time and not the compile, then ignore this post : )
Make should handle incremental build . For incremental link there is an option in gcc but I have no clue how it works.
To speedup compiles, try
ccache
and
distcc if you have a cluster of machines
Ok, according to the ld man page you use -i, and it seems to work about as one would expect. Here I have 5 .c files: a.c, b.c, c.c, d.c, and main.c. I compile them all into *.o object files, then incrementally link a.o and b.o into ab.o, and I link c.o and d.o into cd.o. Finally, I link ab.o, cd.o, and main.o into a finished executable named "thing":
Code:
15:59 aluser@alf:~/test/c/incremental$ cat Makefile
thing: ab.o cd.o main.o
$(CC) -o $@ $^
ab.o: a.o b.o
cd.o: c.o d.o
ab.o cd.o:
$(LD) -i -o $@ $^
16:00 aluser@alf:~/test/c/incremental$ ls
Makefile a.c b.c c.c d.c main.c
16:02 aluser@alf:~/test/c/incremental$ make
cc -c -o a.o a.c
cc -c -o b.o b.c
ld -i -o ab.o a.o b.o
cc -c -o c.o c.c
cc -c -o d.o d.c
ld -i -o cd.o c.o d.o
cc -c -o main.o main.c
cc -o thing ab.o cd.o main.o
16:02 aluser@alf:~/test/c/incremental$ ./thing
Hello, world
I have been trying to figure out how to compile C++ files but it looks like that while I can create the object (.o) files with g++ (using -c option) I cannot link them with ld.
Hm my guess is that it needs extra options to do c++.. Have you tried using g++ with -Wl,-i ?
You are right the -i was what was needed. So I got it working now, just strange that the --help didnt mention it... and man page merely said it could be used.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.