您可以使用链接器存储路径来搜索输出二进制文件,因此不需要LD_LIBRARY_PATH。一些例子:
# Will link fine but at run-time LD_LIBRARY_PATH would be requiredgcc -o blah blah.o -lpcap -L/opt/csw/lib# Without LD_LIBRARY_PATH=/opt/csw/lib it will fail to link, but# it wouldn't be needed at run-timegcc -o blah blah.o -lpcap -Wl,-R/opt/csw/lib# LD_LIBRARY_PATH not needed at link or run-timegcc -o blah blah.o -lpcap -Wl,-{L,R}/opt/csw/lib# This makes it possible to use relative paths; run `readelf -d binary_name`# and you'll see '$ORIGIN/../lib/' in RPATH. This plus `-zorigin` make it look# relative to the binary for libraries at run-timegcc -o blah blah.o -lsomelib -L/whatever/path/floats/your/boat -Wl,-R'$ORIGIN/../lib/' -Wl,-zorigin
..其中:
- 给出的路径
-L
在 链接时使用 - 给定的路径
-R
在 运行时使用
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)