不能 link 静态 boost::iostreams 库

Can't link static boost::iostreams library

我构建了以下代码:

#include <boost/iostreams/filter/zlib.hpp>
#include <iostream>

int main(int argc, char* argv[])
{
  int a = boost::iostreams::zlib::default_compression;
  std::cout << a;
  return 0;
}

使用命令:

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-x32-1_72 -o Source.exe

它可以工作,但前提是 boost_iostreams-mgw63-mt-x32-1_72 是共享库。如果我尝试使用静态库,它会给我以下错误:D:\boost_1_72_0\stage\lib/libboost_iostreams-mgw63-mt-x32-1_72.a(zlib.o):zlib.cpp:(.text+0x124): undefined reference to crc32'

我使用以下命令构建静态库:b2 -a -q -j8 address-model=32 link=static threading=multi toolset=gcc runtime-link=shared variant=release --with-iostreams -sZLIB_INCLUDE="C:\Program Files (x86)\GnuWin32\include" -sZLIB_LIBPATH="C:\Program Files (x86)\GnuWin32\lib" -sBZIP2_INCLUDE="C:\Program Files (x86)\GnuWin32\include" -sBZIP2_LIBPATH="C:\Program Files (x86)\GnuWin32\lib"

如果我将 link=staic 更改为 link=shared,然后将 dll 复制到项目文件夹 - 一切都会好起来的。但我希望程序能够运行 w/o dlls。

有什么问题吗?我如何 运行 和构建程序 w/o 共享库?

短:-Lpath_to_zlib -lz.

Long:如您所知,要在 unix 上解决此问题,您只需添加 -lz 参数即可。 windows 用户也是如此。您只是(更有可能)在您的 PATH 环境变量中没有 zlib.a/lib 位置。所以要解决这个问题,你应该添加 2 个参数:-Lpath_to_zlib -lz.