Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ partial linking instead of archives?

Tags:

c++

g++

linker

I'm pretty new to the C++ build flow, and I'm thinking of switching to use partial linking for my libraries instead of creating ar archives. I'm hoping to reduce link time in an inevitable final compilation step that I have, and I figure partial linking some libraries once could save me time over linking everything in that final step.

Is what I'm describing possible? I figure it should be something along the lines ld -Ur -o mylib.o [components]. Are there important build considerations that I'm not taking into account?

like image 324
cdleary Avatar asked Nov 07 '08 01:11

cdleary


People also ask

What is partial linking?

Produces a single output file that can be used as input to a subsequent link step. Partial linking: Eliminates duplicate copies of debug sections. Merges the symbol tables into one.

What is whole archive?

The /WHOLEARCHIVE option forces the linker to include every object file from either a specified static library, or if no library is specified, from all static libraries specified to the LINK command.


1 Answers

You lose an important effect of having the object files in an ar archive, which is that only the referenced objects will be linked in.

If you have both foo.o with the symbol foo and bar.o with the symbol bar in an ar archive, and only reference the foo symbol, only foo.o would be linked in. If you instead do a partial link, the contents of both will end up in the executable, even if bar is never referenced anywhere.

You could also try a faster linker, like gold.

like image 147
CesarB Avatar answered Sep 28 '22 05:09

CesarB