【发布时间】:2020-07-21 03:16:47
【问题描述】:
更具体地说,支持 zlib(又名 libz)的静态 boost::iostreams。
问题是,当我尝试链接静态库时,它会抛出未解析的符号。同时,当我尝试链接动态库时,一切正常......
我找了好几天的答案,还是找不到。
我用来构建shared库的命令:b2 -a -q -j8 address-model=32 toolset=gcc --with-iostreams link=shared runtime-link=shared -sZLIB_INCLUDE="path" -sZLIB_LIBPATH="path" -sBZIP2_INCLUDE="path" -sBZIP2_LIBPATH="path"
我用来构建static库的命令:b2 -a -q -j8 address-model=32 toolset=gcc --with-iostreams link=static runtime-link=static -sZLIB_INCLUDE="path" -sZLIB_LIBPATH="path" -sBZIP2_INCLUDE="path" -sBZIP2_LIBPATH="path"
程序示例:
#include <iostream>
#include <boost/iostreams/filter/gzip.hpp>
int main(int argc, char* argv[]) {
int a = boost::iostreams::zlib::default_compression;
std::cout << a << std::endl;
return 0;
}
我得到的异常:
D:\boost_1_72_0\stage\lib/libboost_iostreams-mgw63-mt-s-x32-1_72.a(zlib.o):zlib.cpp:(.text+0x124): undefined reference to `crc32'
D:\boost_1_72_0\stage\lib/libboost_iostreams-mgw63-mt-s-x32-1_72.a(zlib.o):zlib.cpp:(.text+0x181): undefined reference to `deflate'
D:\boost_1_72_0\stage\lib/libboost_iostreams-mgw63-mt-s-x32-1_72.a(zlib.o):zlib.cpp:(.text+0x1a1): undefined reference to `inflate'
D:\boost_1_72_0\stage\lib/libboost_iostreams-mgw63-mt-s-x32-1_72.a(zlib.o):zlib.cpp:(.text+0x1cc): undefined reference to `deflateReset'
D:\boost_1_72_0\stage\lib/libboost_iostreams-mgw63-mt-s-x32-1_72.a(zlib.o):zlib.cpp:(.text+0x1e5): undefined reference to `inflateEnd'
D:\boost_1_72_0\stage\lib/libboost_iostreams-mgw63-mt-s-x32-1_72.a(zlib.o):zlib.cpp:(.text+0x201): undefined reference to `inflateReset'
D:\boost_1_72_0\stage\lib/libboost_iostreams-mgw63-mt-s-x32-1_72.a(zlib.o):zlib.cpp:(.text+0x214): undefined reference to `deflateEnd'
D:\boost_1_72_0\stage\lib/libboost_iostreams-mgw63-mt-s-x32-1_72.a(zlib.o):zlib.cpp:(.text+0x3c9): undefined reference to `inflateInit2_'
D:\boost_1_72_0\stage\lib/libboost_iostreams-mgw63-mt-s-x32-1_72.a(zlib.o):zlib.cpp:(.text+0x469): undefined reference to `deflateInit2_'
collect2.exe: error: ld returned 1 exit status
makefile:15: recipe for target 'Source.exe' failed
mingw32-make: *** [Source.exe] Error 1
The terminal process terminated with exit code: 1
更新: 此外,如果问题可能与 zlib 或 bz2 有关: 我在这里得到了 bz2 库:http://gnuwin32.sourceforge.net/packages/bzip2.htm 和 zlib 在这里:http://gnuwin32.sourceforge.net/packages/zlib.htm 我尝试用他们的 win32 makefile 自己构建 zlib。我得到了 libz.a 并尝试使用它进行构建,但没有任何改变。
【问题讨论】:
-
我使用以下命令编译项目:
g++ -Wall -ID:\boost_1_72_0 -c -o Source.o Source.cpp和g++ -Wall -ID:\boost_1_72_0 Source.o -LD:\boost_1_72_0\stage\lib -lboost_iostreams-mgw63-mt-s-x32-1_72 -o Source.exe -
尝试在链接命令末尾添加
-lz -
-lz 是一个非常有用的东西,linux 有,windows 没有。但是你知道,我什至没有尝试测试使用这个命令。它可以工作(如果我在我的机器 ofc 上指定 zlib.a 位置)