c++ - Boost iostreams 库存在,但我无法链接它

标签 c++ linker linker-errors shared-objects boost-iostreams

我知道有很多类似的问题,但我的问题有点不同,而且没有帮助我。

我正在使用 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

关于我:

  • 操作系统:Debian 7 Wheezy
  • 编。语言:C++
  • 编译器:g++ (Debian 4.7.2-5) 4.7.2
  • 链接器:GNU ld(适用于 Debian 的 GNU Binutils)2.22
  • boost 库版本:1.49(来自 debian 仓库)

谢谢!

编辑:

正确的选项应该是-lboost_iostreams,而不是-lboost-iostreams

编辑 2:

编辑后我的命令是:

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

最佳答案

一般来说,您不会直接调用ld,而是调用gccg++。这可能会在链接时添加正确的搜索路径。

如果您显式链接,则不得包含 -l 标志。只需将 /usr/lib/libboost_iostreams.a/usr/lib/libboost_iostreams.so 添加到您要链接的文件列表中即可。

-l 标志添加lib 前缀和.so.a 后缀。

关于c++ - Boost iostreams 库存在,但我无法链接它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17950840/

相关文章:

c++ - 如何使用 C++ 操作 PE 二进制文件中的节地址表?

visual-studio-2010 - VS2010如何设置_ITERATOR_DEBUG_LEVEL?

c++ - 对某些 OpenGL 函数的 undefined reference (如果它们尚未在 main 中调用)

c++ - 语句包含自身

c++ - typedef decltype 函数指针未返回正确的输出(cout)

c++ - 如何自动链接到共享库的依赖项

python - 使用 Cython 将 Python 代码编译为静态链接的可执行文件

c++ - vc++ 无法解析的外部符号(无法调用构造函数)

c - 链接时出现 undefined reference 错误

c++ - glutSpecialFunc 只捕获一些键