Question

I'd like to experiment with Google's tcmalloc on Linux... I have a huge project here, with hundreds of qmake generated Makefile's... I'd like to find a way to get gcc to globally link against tcmalloc (like it does with libc)... Is this possible? Or will I have to edit every Makefile?

(I'd prefer not to edit all the pro files as there are hundreds of them)

(Also, we've already tried the LD_PRELOAD method and it's not working quite right)...

Was it helpful?

Solution

How do your makefiles access the compiler (gcc/g++/cc/c++)?

If it's just by name (g++), and not by explicit path (/usr/bin/g++), you can simply create a replacement g++ in whatever directory you prefer, and prepend that directory to your path.

E.g.: Create a   ~/mytmpgccdir/g++   file:

#!/bin/tcsh -f
exec /usr/bin/g++ -Lfoo -lfoo $*:q

Adding whatever extras (-Lfoo -lfoo) you like, either before or after the other arguments ($*:q).

Then pre-pend it to your path and make normally.

#tcsh version
% set path = ( ~/mytmpgccdir/  $path:q )
% make clean
% make

p.s. If it is by explicit name, you may be able to override it on the command line. Something like:   make all GCC=~/mytmpgccdir/gcc

p.p.s If you do use LD_PRELOAD, you might want a script like this to setenv LD_PRELOAD before running your program. Otherwise it's easy to wind up LD_PRELOAD'ing on every command like /bin/ls, make, g++, etc.

OTHER TIPS

First, check the qmake documentation. There is an easy way to specify (in a .pro file) that a certain library should always be linked in.

Also, since you are just experimenting, simply use LD_PRELOAD - no recompilation necessary:

LD_PRELOAD="/usr/lib/foo/libtcmalloc.so" ./your_program

You do not have to have linked "your_program" against google's tcmalloc library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top