boost iostreams library exist but i am unable link it

痴心易碎 提交于 2019-12-10 16:17:50

问题


I know that the re plenty of similar questions, but mine is litle bit different and non them helped me.

I am using boost-iostreams library and here is my problem, i tried to link my program with libraries:

ld -I/usr/include/boost/iostreams/ -I/usr/include/boost/iostreams/device/  -L/usr/lib/libboost_iostreams.so -lboost-iostreams fd.o -o x 

And the result was:

ld: cannot find -lboost-iostreams

When i tried to write it explicitly:

ld -I/usr/include/boost/iostreams/ -I/usr/include/boost/iostreams/device/  --library /usr/lib/libboost_iostreams.so -lboost-iostreams fd.o -o x

It told me that the library dont exist:

ld: cannot find -l/usr/lib/libboost_iostreams.so
ld: cannot find -lboost-iostreams

But it does:

$ 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

About me:

  • OS: Debian 7 Wheezy
  • prog. lang.: c++
  • compiler: g++ (Debian 4.7.2-5) 4.7.2
  • linker: GNU ld (GNU Binutils for Debian) 2.22
  • boost library ver.: 1.49 ( from debian repo )

Thanks!

EDIT:

The right option should be -lboost_iostreams, not -lboost-iostreams

EDIT2:

After edit my command was:

ld fd.o -I/usr/include/boost/iostreams/ -I/usr/include/boost/iostreams/device/ -o x $(LIB_PATH) -lboost_iostreams

Where libpath is ONE of following:

LIB_PATH=
LIB_PATH=-L/usr/lib/
LIB_PATH=/usr/lib/libboost_iostreams.so
LIB_PATH=/usr/lib/libboost_iostreams.a

but the result is still:

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

回答1:


Generally speaking you do not call ld directly but rather call gcc or g++ instead. This might add the correct search paths when linking.

If you link explicitly, you must not include the -l flag. Just add /usr/lib/libboost_iostreams.a or /usr/lib/libboost_iostreams.so to the list of files that you are linking.

The -l flag add the lib prefix and the .so or .a suffix.



来源:https://stackoverflow.com/questions/17950840/boost-iostreams-library-exist-but-i-am-unable-link-it

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