C++ 使用 zlib 编译 boost
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4937723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compiling boost with zlib
提问by cppanda
I'm compiling boost with bjam under Windows 7 (64bit-should be irrelevant)
我正在 Windows 7 下用 bjam 编译 boost(64 位应该无关紧要)
D:\development\boost\boost_1_44\libs\iostreams\build>bjam stage ^
--toolset=msvc-10.0 link=static ^
--build-type=complete ^
-s ZLIB_SOURCE=C:\zlib125-dll ^
-s ZLIB_LIBPATH=C:\zlib125-dll\lib ^
-s ZLIB_INCLUDE=C:\zlib125-dll\include ^
-s ZLIB_BINARY=C:\zlib125-dll
But I only get
但我只得到
stage/libboost_iostreams-vc100-mt-gd-1_44.lib
bin.v2/libs/iostreams/build/msvc-10.0/debug/threading-multi/boost_iostreams-vc100-mt-gd-1_44.dll
bin.v2/libs/iostreams/build/msvc-10.0/debug/threading-multi/boost_iostreams-vc100-mt-gd-1_44.lib
bin.v2/libs/iostreams/build/zlib/msvc-10.0/debug/threading-multi/boost_zlib-vc100-mt-gd-1_44.dll
bin.v2/libs/iostreams/build/zlib/msvc-10.0/debug/threading-multi/boost_zlib-vc100-mt-gd-1_44.lib
but stage/libboost_zlib-vc100-mt-gd-1_44.lib
is missing.
但stage/libboost_zlib-vc100-mt-gd-1_44.lib
不见了。
Am I compiling something wrong?
我编译错了吗?
when I try running my project that worked well with boost and self-compiled boost/thread libraries I get the following error when I include the boost zlib stuff
当我尝试运行与 boost 和自编译 boost/thread 库配合良好的项目时,当我包含 boost zlib 内容时出现以下错误
6>LINK : fatal error LNK1104: cannot open file 'libboost_zlib-vc100-mt-gd-1_44.lib'
Does anyone know what I'm doing wrong?
有谁知道我做错了什么?
采纳答案by Ferruccio
It took me a while to get Boost to build correctly with zlib support. I blogged about it here.
我花了一段时间才让 Boost 在 zlib 支持下正确构建。我在这里写了关于它的博客。
To sum it up, the problem I ran into was that at some point zlib no longer included a gzio.c
source file. The jamfile for the Boost build system (jamfile.v2) had a reference to the gzio module which caused it fail. The solution was to remove that reference before building.
总而言之,我遇到的问题是在某些时候 zlib 不再包含gzio.c
源文件。Boost 构建系统 (jamfile.v2) 的 jamfile 引用了导致它失败的 gzio 模块。解决方案是在构建之前删除该引用。
I'm not sure this answer is relevant any longer, unless you're trying to build an old version of Boost. I believe the original build issue has been fixed in more recent versions of Boost.
我不确定这个答案是否不再重要,除非您正在尝试构建旧版本的 Boost。我相信最初的构建问题已在更新版本的 Boost 中得到修复。
回答by ecotax
I did manage to build them using the option
-sZLIB_SOURCE="C:\zlib-1.2.5"
Note there is no space after the -s and the quotes around the path.
我确实设法使用选项
-sZLIB_SOURCE="C:\zlib-1.2.5"来构建它们
注意 -s 和路径周围的引号之后没有空格。
回答by Antoni
I had the same problem (Windows 7 Visual Studio) and I believe the issue is not in how you build boost.
我遇到了同样的问题(Windows 7 Visual Studio),我相信问题不在于你如何构建 boost。
1) As ecotax, there should not be a space after the -s 2) When running bjam, add the flag --debug-configuration. If in the output you do not see errors and it prints out something like
1) 作为ecotax,-s 后不应有空格 2) 运行bjam 时,添加标志--debug-configuration。如果在输出中您没有看到错误,它会打印出类似
notice: iostreams: using prebuilt zlib
注意:iostreams:使用预构建的 zlib
then it has found your zlib copy, which it is good.
然后它找到了您的 zlib 副本,这很好。
3) Notice that the library libboost_zlib-vc100-mt-gd-1_44.lib should not be produced.
3) 请注意,不应生成库 libboost_zlib-vc100-mt-gd-1_44.lib。
4) When you compile your application in Visual Studio, seems that Boost.Iostreams auto-linking still wants libboost_zlib-vc100-mt-gd-1_44.lib and reports a link error.
4) 在 Visual Studio 中编译应用程序时,似乎 Boost.Iostreams 自动链接仍然需要 libboost_zlib-vc100-mt-gd-1_44.lib 并报告链接错误。
What it worked for me (I founded googling) was to add to the preprocessor definitions the flag
它对我有用(我创立了谷歌搜索)是将标志添加到预处理器定义中
BOOST_IOSTREAMS_NO_LIB
BOOST_IOSTREAMS_NO_LIB
回答by Evgeny Yashin
For guys, who compiling, using prebuilt 'zlib'. These steps needs to be done:
对于使用预构建的“zlib”进行编译的人。需要完成以下步骤:
- Download and build 'zlib'
- Run b2.exe --with-iostreams -s ZLIB_BINARY=zlib -s ZLIB_INCLUDE=C:/Sys/zlib-1.2.7/Include -s ZLIB_LIBPATH=C:/Sys/zlib-1.2.7/Lib release
- 下载并构建“zlib”
- 运行 b2.exe --with-iostreams -s ZLIB_BINARY=zlib -s ZLIB_INCLUDE=C:/Sys/zlib-1.2.7/Include -s ZLIB_LIBPATH=C:/Sys/zlib-1.2.7/Lib release
Update paths to your local installation zlib folder. This way, Boost will embed into libboost_iostreams the gzip.cpp, zlib.cpp files. No libboost_zlib will be generated.
更新本地安装 zlib 文件夹的路径。这样,Boost 就会将 gzip.cpp、zlib.cpp 文件嵌入到 libboost_iostreams 中。不会生成 libboost_zlib。
- At your source file add this lines (somewhere in stdafx.h, before including Boost.Iostream headers):
- 在您的源文件中添加以下行(在 stdafx.h 中的某处,在包含 Boost.Iostream 标头之前):
--
——
#ifdef _DEBUG
#define BOOST_ZLIB_BINARY zlibd
#else
#define BOOST_ZLIB_BINARY zlib
#endif
This tells that you don't want to link against libboost_zlib, but you provide precompiled zlib library instead.
这表明您不想链接 libboost_zlib,而是提供预编译的 zlib 库。
- At your project settings provide path to zlib.lib file.
- It should compile and link now.
- 在您的项目设置中提供 zlib.lib 文件的路径。
- 它现在应该编译和链接。
回答by user2387519
I took a combination of advice from other answers here and this is what I did:
我在这里综合了其他答案的建议,这就是我所做的:
Extract zlib to C:\zlib\zlib-1.2.11.
将 zlib 解压到 C:\zlib\zlib-1.2.11。
Use CMake to configure and generate MS Visual Studio 2017 project and use MS Visual Studio 2017 to build the project. I built it in place so that C:\zlib\zlib-1.2.11 now contains (in addition to previous contents) directories lib and include.
使用CMake配置生成MS Visual Studio 2017项目,使用MS Visual Studio 2017构建项目。我在适当的位置构建了它,以便 C:\zlib\zlib-1.2.11 现在包含(除了以前的内容)目录 lib 和 include。
Extract Boost 1.67.0 to C:\Boost\boost_1_67_0.
将 Boost 1.67.0 提取到 C:\Boost\boost_1_67_0。
(Be on drive C:)
(在驱动器 C 上:)
cd \Boost\boost_1_67_0
bootstrap.bat
set ZLIB_SOURCE="C:\zlib\zlib-1.2.11"
set ZLIB_INCLUDE="C:\zlib\zlib-1.2.11\include"
set ZLIB_LIBPATH="C:\zlib\zlib-1.2.11\lib"
The following line built libboost_iostreams and it did put libboost_zlib files in C:\Boost\boost_1_67_0\stage\lib:
以下行构建了 libboost_iostreams 并将 libboost_zlib 文件放在 C:\Boost\boost_1_67_0\stage\lib 中:
b2 --debug-configuration --with-iostreams -sZLIB_SOURCE="C:\zlib\zlib-1.2.11" -sZLIB_INCLUDE="C:\zlib\zlib-1.2.11\include" -sZLIB_LIBPATH="C:\zlib\zlib-1.2.11\lib"
The following line built the rest of Boost:
以下行构建了 Boost 的其余部分:
b2 -sZLIB_SOURCE="C:\zlib\zlib-1.2.11" -sZLIB_INCLUDE="C:\zlib\zlib-1.2.11\include" -sZLIB_LIBPATH="C:\zlib\zlib-1.2.11\lib"
Don't know if this is the most optimal way to do it, but it did build the libboost_zlib lib files.
不知道这是否是最好的方法,但它确实构建了 libboost_zlib 库文件。
回答by N. Fan
set ZLIB_SOURCE="c:\zlib"
set ZLIB_SOURCE="c:\zlib"
set ZLIB_INCLUDE="c:\zlib"
set ZLIB_INCLUDE="c:\zlib"
.\b2
.\b2
.\bjam
will not build but .\b2
will build the library: stage/libboost_zlib-vc100-mt-gd-1_44.lib
.\bjam
不会构建但.\b2
会构建库:stage/libboost_zlib-vc100-mt-gd-1_44.lib