基于boost的程序的静态链接——zlib问题
Static linking for boost-based program -- zlib problem
我正在尝试构建一个使用Boost Iostreams库的程序,并创建一个静态链接的可执行文件。我在RHEL7和Ubuntu 18.04上都尝试过,但都出现了类似的错误。编译器是GCC。在Ubuntu上:
$ g++ -o demultiplexer.static demultiplexer.cpp -O3 -std=c++11 -static -lz -lboost_iostreams
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libboost_iostreams.a(zlib.o): In function `boost::iostreams::detail::zlib_base::after(char const*&, char*&, bool)':
(.text+0xf8): undefined reference to `crc32'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libboost_iostreams.a(zlib.o): In function `boost::iostreams::detail::zlib_base::reset(bool, bool)':
(.text+0x171): undefined reference to `deflateReset'
(.text+0x186): undefined reference to `inflateEnd'
(.text+0x199): undefined reference to `inflateReset'
(.text+0x1b1): undefined reference to `deflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libboost_iostreams.a(zlib.o): In function `boost::iostreams::detail::zlib_base::do_init(boost::iostreams::zlib_params const&, bool, void* (*)(void*, unsigned int, unsigned int), void (*)(void*, void*), void*)':
(.text+0x394): undefined reference to `inflateInit2_'
(.text+0x3e2): undefined reference to `deflateInit2_'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libboost_iostreams.a(zlib.o): In function `boost::iostreams::detail::zlib_base::xdeflate(int)':
(.text+0x144): undefined reference to `deflate'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libboost_iostreams.a(zlib.o): In function `boost::iostreams::detail::zlib_base::xinflate(int)':
(.text+0x154): undefined reference to `inflate'
collect2: error: ld returned 1 exit status
怎么了,我该如何防止这些链接器错误?尝试的替代方案:
$ g++ -o demultiplexer.static demultiplexer.cpp -O3 -std=c++11 /usr/lib/x86_64-linux-gnu/libz.a /usr/lib/x86_64-linux-gnu/libboost_iostreams.a
(same as above)
$ g++ -o demultiplexer.static demultiplexer.cpp -O3 -std=c++11 -Wl,-Bstatic -lz -lboost_iostreams
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
正如@some programmer dude的评论中所说;所需要的只是更改订单!
g++ -o demultiplexer.static demultiplexer.cpp -O3 -std=c++11 -static -lboost_iostreams -lz
这适用于
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 为char数组调整zlib-zpipe
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 基于boost的程序的静态链接——zlib问题
- SDL和zlib问题,不能从zip创建有效的组结构
- zlib内存不足的问题