【问题标题】:Can't link static boost::iostreams library无法链接静态 boost::iostreams 库
【发布时间】:2020-07-19 20:14:36
【问题描述】:

我构建了以下代码:

#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 复制到项目的文件夹 - 一切都会好起来的。但我希望程序在没有 dll 的情况下工作。

有什么问题?如何在没有共享库的情况下运行和构建程序?

【问题讨论】:

    标签: c++ gcc boost gnu zlib


    【解决方案1】:

    短:-Lpath_to_zlib -lz.

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

    【讨论】:

      猜你喜欢
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多