Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 基于boost程序的静态链接——zlib问题_C++_Gcc_Boost - Fatal编程技术网

C++ 基于boost程序的静态链接——zlib问题

C++ 基于boost程序的静态链接——zlib问题,c++,gcc,boost,C++,Gcc,Boost,我正在尝试构建一个使用boostiostreams库的程序,并创建一个静态链接的可执行文件。我在RHEL7和Ubuntu18.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

我正在尝试构建一个使用boostiostreams库的程序,并创建一个静态链接的可执行文件。我在RHEL7和Ubuntu18.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

正如@someprogrammerdude的评论;所需要的只是改变顺序

g++ -o demultiplexer.static demultiplexer.cpp -O3 -std=c++11 -static -lboost_iostreams -lz

这是有效的

订单问题。如果库A依赖于库B,那么在命令行中A必须位于B之前。