Bugzilla – Bug 3
wrong RPATH in build.py
Last modified: 2008-07-01 13:32:11 UTC
In build.py the RPATH for executable is determined by the following: lib_path = os.path.join (build_root, 'lib') ... module_builder = env.Program (target = filename, source = objects, LIBPATH=lib_path, LIBS=libs, RPATH=lib_path) this result in all built executables being unable to find the needed shared libraries: $ ./sample-simulator ./sample-simulator: error while loading shared libraries: libsimulator.so: cannot open shared object file: No such file or directory which of course can be fixed by setting LD_LIBRARY_PATH, but I think this was not the original intention of the developers. The problem is that the RPATH is wrong: $ objdump -p sample-packet | grep RPATH RPATH build-dir/dbg-shared/lib A possible fix is to change build.py this way: module_builder = env.Program (target = filename, source = objects, LIBPATH=lib_path, LIBS=libs, RPATH='../lib') which obtains this effect: $ objdump -p sample-packet | grep RPATH RPATH ../lib and (at least on linux) it works: $ ./sample-packet send data=2 received data=2 Using a relative path has the benefits that binaries and libraries can be installed in whatever prefix and keep on working. A slightly more complex approach is described here: http://www.scons.org/wiki/UsingOrigin which if I understood correctly should have the additional benefit of working on SUN systems, too. Anyway, I didn't try it. Regards, Nicola
You are supposed to invoke binaries from the top-level directory and not from the 'bin' directory: The following will work: ./build-dir/opt-shared/bin/run-tests It was done that way to save you from having to cd to the correct directory. I could be convinced to change the current way of doing this to use absolute paths which would allow you to invoke the binary from any directory but this would break the build if you move around the source tree.
A better solution is then to use $ORIGIN symbol (the "slightly more complex approach" I mentioned above) which has the benefits of being independent of the working directory: baldo@pcsignet08:/locale/baldo/src/ns-3/build-dir/dbg-shared/bin$ objdump -p sample-packet | grep RPATH RPATH $ORIGIN/../lib baldo@pcsignet08:/locale/baldo/src/ns-3/build-dir/dbg-shared/bin$ ./sample-test PASS Callback PASS ReferenceList PASS My baldo@pcsignet08:/locale/baldo/src/ns-3$ ./build-dir/dbg-shared/bin/sample-test PASS Callback PASS ReferenceList PASS My
Created attachment 1 [details] patch implementing solution proposed in comment #2
I applied a patch similar to the one you suggested. Do you have any idea whether or not your approach will work also on OSX ? (I don't have a system to test it on) thanks !
For reference, I found the following: http://www.flipcode.com/cgi-bin/fcarticles.cgi?show=63919 which seems to imply that ORIGIN will not work but that something else will.
we use waf to build the code so, the scons scripts are dead.