我知道有很多类似的问题,但我的问题有点不同,不是它们帮助了我。
我正在使用boost-iostreams库,这是我的问题,我试图将我的程序链接到库:
ld -I/usr/include/boost/iostreams/ -I/usr/include/boost/iostreams/device/ -L/usr/lib/libboost_iostreams.so -lboost-iostreams fd.o -o x 结果是:
ld: cannot find -lboost-iostreams当我试图显式地写它时:
ld -I/usr/include/boost/iostreams/ -I/usr/include/boost/iostreams/device/ --library /usr/lib/libboost_iostreams.so -lboost-iostreams fd.o -o x它告诉我图书馆不存在:
ld: cannot find -l/usr/lib/libboost_iostreams.so
ld: cannot find -lboost-iostreams但它做到了:
$ ls -l /usr/lib/libboost_iostreams*
-rw-r--r-- 1 root root 204682 feb 4 05:28 /usr/lib/libboost_iostreams.a
lrwxrwxrwx 1 root root 20 feb 4 05:28 /usr/lib/libboost_iostreams-mt.a -> libboost_iostreams.a
lrwxrwxrwx 1 root root 28 feb 4 05:28 /usr/lib/libboost_iostreams-mt.so -> libboost_iostreams.so.1.49.0
lrwxrwxrwx 1 root root 28 feb 4 05:28 /usr/lib/libboost_iostreams.so -> libboost_iostreams.so.1.49.0
-rw-r--r-- 1 root root 94280 feb 4 05:28 /usr/lib/libboost_iostreams.so.1.49.0关于我:
谢谢!
编辑:
正确的选项应该是-lboost_iostreams,而不是-lboost-iostreams
EDIT2:
编辑后,我的命令是:
ld fd.o -I/usr/include/boost/iostreams/ -I/usr/include/boost/iostreams/device/ -o x $(LIB_PATH) -lboost_iostreams其中libpath是以下内容之一:
LIB_PATH=
LIB_PATH=-L/usr/lib/
LIB_PATH=/usr/lib/libboost_iostreams.so
LIB_PATH=/usr/lib/libboost_iostreams.a但结果仍然是:
ld: warning: cannot find entry symbol _start; defaulting to 000000000804cc10
fd.o: In function `__static_initialization_and_destruction_0(int, int)':
fd.cpp:(.text+0xd6): undefined reference to `__dso_handle'
ld: x: hidden symbol `__dso_handle' isn't defined
ld: final link failed: Bad value
make: *** [x] Error 1发布于 2013-07-30 17:10:31
一般来说,您不直接调用ld,而是调用gcc或g++。这可能会在链接时添加正确的搜索路径。
如果显式链接,则不能包含-l标志。只需将/usr/lib/libboost_iostreams.a或/usr/lib/libboost_iostreams.so添加到要链接的文件列表中即可。
-l标志添加lib前缀和.so或.a后缀。
https://stackoverflow.com/questions/17950840
复制相似问题