I’ve been developing an program of late using both g++ 4.6 and g++ 4.7. I’m currently taking advantage of a lot of the c++11 features.
I made this decision thinking that I would be able to just bundle the libs along with the program in a sub directory and use LD_LIBRARY_PATH. I have since discovered that this is causing my program to segfault. I probably should have tested this a little earlier on huh. It appears to be the bundled libc.so.6 that is causing it (possibly others, but definitely libc).
In the past I have used this technique where it has not been possible to install libs and it has worked fine, but I have never needed to include the libc and libstdc++ along with the program.
Is there a way around this problem, or am I going to have to roll back to an older c++ / libc / libstdc++ version? (and the nightmare of code changes that comes with it)
I would avoid relying on
LD_LIBRARY_PATH— use it for testing or development but not production deployments.Instead link with
'-Wl,-rpath,$ORIGIN'to create aDT_RPATHtag containing$ORIGINwhich means the dynamic linker will look for shared libs in the same dir as the executable (or e.g. use ‘-Wl,-rpath,$ORIGIN/../lib’ to look in../lib)If any parts of your program were built with G++ 4.7 then you need to use the libstdc++.so from GCC 4.7 at runtime.
But if the problem is in libc.so.6 it’s not a GCC issue, and my advice would be do not try to bundle libc … trying to replace the system libc probably isn’t a good idea.