When I compile a c++ program using g++ from the command line and then do ldd a.out
ldd is able to find libstdc++.a(libstdc++.so.6)
When I build a c++ ruby extension ldd myext.so
cannot find libstdc++.a(libstdc++.so.6), and require 'myext'
fails to load, with a complaint about not being able to find libstdc++.
If I run g++ -v I see the following output:
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/big_long_path....
Target: powerpc-ibm-aix7.1.0.0
Configured with: ../gcc-4.8.2/configure .....
Thread model: aix
gcc version 4.8.2 (GCC)
Now if I set my LIBPATH
to include that big_long_path
export LIBPATH=/big_long_path....:$LIBPATH
ldd myext.so
is able to find libstdc++ and my require 'myext'
works (returns true)
This might be OK, but I would rather not have to have users muck with their LIBPATH. Is there something I can add to my Makefile that allow the generated myext.so to find libstdc++ (and libgcc) in the location pointed to by that big_long_path I see in the COLLECT_LTO_WRAPPER line that I see when I run g++ -v ?
Update
The first link in the accepted answer below really helped me understand what was going on, and I was able to get ldd to not complain about libstdc++ by adding -blibpath:big_long_path:/usr:/usr/lib to the LDFLAGS in the Makefile.
But for some reason when ruby tried to load the ext it still failed. This made me think that ruby was somehow adjusting the LIBPATH. In the end my solution was to put a symbolic link to the libstdc++ and libgcc_s in the lib directory of the ruby install. The thought was ruby must need to search for extension shared objects, so I figured I would take advantage of this and place these two libs in the path that ruby must search. The only thing I am wondering is if I should just copy the libstdc++ and libgcc_s rather than symbolically link them?