Tips on reducing c++ linking time

I dealt with this for years at a previous job. The GNU linker simply has serious performance problems when linking large numbers of static libraries. At one point, link time was on par with compile time, which we found so strange we actually investigated this and figured it out.

You can try to merge your static libraries into a "super-object" before linking. Instead of linking like this:

$ g++ -o program program.o $STATIC_LIBS

You could try this:

$ ld -r -o libraries.o --whole-archive $STATIC_LIBS
$ g++ -o program program.o libraries.o

Note that this method gives the linker less opportunity to exclude unused object code, so your binaries may increase in size somewhat.


create a ramdisk ,compile to that and link to harddisk.

since you're using a lot of static libraries ,you can create a giant library containing all thos libraries so you end up with one libray. remove all libraries from your lib-list and add th giant one. This reduces openings of file to 1 for the libraries and may speed up reading actions.

Tags:

C++

Linker