embedding absolute path for shared libraries

纵然是瞬间 提交于 2020-01-03 19:01:05

问题


Using a vendor provided cross-compiling toolchain (apparently an OpenEmbedded derivative), I'm unable to embed the absolute path to third-party (open source, compiled in house)libraries. With the following gcc command line:

arm-linux-gcc test_connect_send.o gprs_connect.o \
    /package/host/myvendor.com/API-R-2.0.0/Release/Libraries/libgprs_stuff.so \
    /package/host/myvendor.com/API-R-2.0.0/Release/Libraries/libpower_supply_stuff.so \
    /package/host/myvendor.com/API-R-2.0.0/Release/Libraries/libgsm_stuff.so \
    /package/host/myvendor.com/API-R-2.0.0/Release/Libraries/libtcp_stuff.so \
    /package/host/aspl.es/vortex-1.1.0/lib/libvortex-1.1.so \
    /package/host/aspl.es/axl-0.5.6/lib/libaxl.so.0  -o test_connect_send

objdump says:

Dynamic Section:
  NEEDED      /package/host/myvendor.com/API-R-2.0.0/Release/Libraries/libgprs_stuff.so
  NEEDED      /package/host/myvendor.com/API-R-2.0.0/Release/Libraries/libpower_supply_stuff.so
  NEEDED      /package/host/myvendor.com/API-R-2.0.0/Release/Libraries/libgsm_stuff.so
  NEEDED      /package/host/myvendor.com/API-R-2.0.0/Release/Libraries/libtcp_stuff.so
  NEEDED      libvortex-1.1.so.0
  NEEDED      libaxl.so.0
  NEEDED      libgcc_s.so.1
  NEEDED      libc.so.6

Notice how my vendor's libraries do have their full path, while aspl's don't. Also, notice how the name embedded is different from the one I specified on the command line. I'd like to know why (who is messing with my paths), and how to solve it.

p.s.: I know about RPATH, that's not the answer I'm looking for


回答1:


My guess would be that the vendor supplied libs set the SONAME to the full installed path.




回答2:


arm-linux-gcc -print-file-name does not show anything suprising:

arm-linux-gcc -print-file-name=/package/host/aspl.es/axl-0.5.6/lib/libaxl.so.0.0.0 /package/host/aspl.es/axl-0.5.6/lib/libaxl.so.0.0.0 arm-linux-gcc -print-file-name=/package/host/aspl.es/axl-0.5.6/lib/libaxl.so.0.0 /package/host/aspl.es/axl-0.5.6/lib/libaxl.so.0.0 arm-linux-gcc -print-file-name=/package/host/aspl.es/axl-0.5.6/lib/libaxl.so.0 /package/host/aspl.es/axl-0.5.6/lib/libaxl.so.0 arm-linux-gcc -print-file-name=/package/host/aspl.es/axl-0.5.6/lib/libaxl.so /package/host/aspl.es/axl-0.5.6/lib/libaxl.so

The resulting binary does not run without LD_LIBRARY_PATH defined, nor does it have a DT_RPATH (although that might certainly help, suggestions?)

I don't want to rely on /etc/ld.so.conf being properly set, and thus I want absolute paths everywhere.

Note that suggestions might well point to the compilation of the third-party libraries, which as of now are compiled with:

make distclean; LDFLAGS=-L/package/host/myvendor.com/arm9-linux-toolchain-2.1/prefix/arm-linux/lib CC=/package/host/myvendor.com/arm9-linux-toolchain-2.1/prefix/bin/arm-linux-gcc ~/wd/sources/contrib/axl/configure --prefix=/shared/syst/arm9-linux-abtrack/package/host/aspl.es/axl-0.5.6 --host=armv4tl-unknown-linux-gnu --disable-axl-knife --disable-axl-babel --disable-axl-log --disable-axl-test && make

make distclean; AXL_LIBS="-L/shared/syst/arm9-linux-abtrack/package/host/aspl.es/axl-0.5.6/lib/ -laxl -lm" AXL_CFLAGS=-I/shared/syst/arm9-linux-abtrack/package/host/aspl.es/axl-0.5.6/include/axl CC=/package/host/myvendor.com/arm9-linux-toolchain-2.1/prefix/bin/arm-linux-gcc LDFLAGS="-L/package/host/myvendor.com/arm9-linux-toolchain-2.1/prefix/arm-linux/lib" ~/wd/sources/contrib/vortex/configure --prefix=/shared/syst/arm9-linux-abtrack/package/host/aspl.es/vortex-1.1.0 --disable-http-support --disable-pull-support --disable-tunnel-support --disable-xml-rpc-support-gen --disable-xml-rpc-support --disable-sasl-support --disable-vortex-log --disable-vortex-client --host=armv4tl-unknown-linux-gnu && make

Any autofoo tips for embedding --prefix in compiled libraries?




回答3:


This is an old question, but I thought I'd add a possible answer anyways.

Just based on the info you've given, could it be that the full path names aren't included for aspl because the aspl libraries you've specified are soft links? If you do a long list on, for instance, /package/host/aspl.es/vortex-1.1.0/lib/libvortex-1.1.so it will show that it's a link to libvortex-1.1.so.0 (with no full pathname).

So, if you still want to embedded the full path, then you need to use the full path to the actual library, not the linked library.



来源:https://stackoverflow.com/questions/1124809/embedding-absolute-path-for-shared-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!