C++ 为静态链接构建 Boost (MinGW)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/494629/
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
Building Boost for static linking (MinGW)
提问by Adam
I'm building Boost (I'm using System and FileSystem) for MinGW using bjam:
我正在使用 bjam 为 MinGW 构建 Boost(我正在使用系统和文件系统):
bjam --toolset=gcc stage
And it builds fine, but I want to be able to statically link to it (I have to have a single file for the final product) so I tried:
它构建得很好,但我希望能够静态链接到它(我必须为最终产品创建一个文件),所以我尝试了:
bjam --link=static --toolset=gcc stage
But I get the same output. Any ideas?
但我得到相同的输出。有任何想法吗?
editsecond question in a row I've answered moments after posting :p guess I'll leave this up here for others though.
连续编辑第二个问题我在发布后不久就回答了:p 我想我会把这个留给其他人。
bjam --build-type=complete --toolset=gcc stage
Will build both dynamic and static for sure.
肯定会同时构建动态和静态。
回答by Laserallan
I think link is a property as opposed to an option for bjam. That means that there should be no -- before it.
我认为链接是一个属性,而不是 bjam 的一个选项。这意味着在它之前不应该有-。
This is my command line for building only static libraries (visual c++ though):
这是我仅用于构建静态库的命令行(尽管是 Visual C++):
bjam install --toolset=msvc variant=release link=static threading=multi runtime-link=static
Mapping that to your original build command I would say it should look something like this:
将其映射到您的原始构建命令,我会说它应该是这样的:
bjam --toolset=gcc link=static stage
or perhaps:
也许:
bjam stage --toolset=gcc link=static
Try running
尝试跑步
bjam --help
for more info on properties and options for bjam.
有关 bjam 的属性和选项的更多信息。
回答by Ashley Smart
Just want note that with the newer boost (Feb 2011) you need to build bjam as well now.. for some reason the current downloadable bjam doesn't work cleanly.
只是要注意,使用较新的 boost(2011 年 2 月),您现在还需要构建 bjam。出于某种原因,当前可下载的 bjam 无法正常工作。
So first:
所以首先:
cd ...\boost_1_45_0\tools\build\v2\engine\src
cd ...\boost_1_45_0\tools\build\v2\engine\src
build.bat mingw
build.bat mingw
Youll need to add bjam to the PATH (from control panel, not just on the cmd prompt). Then
您需要将 bjam 添加到 PATH(从控制面板,而不仅仅是在 cmd 提示符下)。然后
cd ...\boost_1_45_0\
cd ...\boost_1_45_0\
bjam --build-type=complete --toolset=gcc stage
bjam --build-type=complete --toolset=gcc stage
My setup is Vista, Boost 1.45, MinGW 4.5, and building from cmd.exe not msys.
我的设置是 Vista、Boost 1.45、MinGW 4.5,并且从 cmd.exe 而非 msys 构建。
http://code-slim-jim.blogspot.com/2011/02/boost-in-vista-using-mingw-and-cmdexe.html
http://code-slim-jim.blogspot.com/2011/02/boost-in-vista-using-mingw-and-cmdexe.html
回答by Fredrik Jansson
I have not built this myself in MinGW but I believe your first build will output both dynamic and static libraries and the second only static ones, so if you did not clean the build directories in between builds it will probably look the same.
我自己没有在 MinGW 中构建过这个,但我相信你的第一个构建会输出动态和静态库,第二个只是静态库,所以如果你没有清理构建之间的构建目录,它可能看起来是一样的。
When you write "I have to have a single file..." do you mean you need a single library containing all boost libraries? If so, I suspect you may have to 'ar' them together yourself.
当您写“我必须有一个文件...”时,您的意思是您需要一个包含所有 boost 库的库吗?如果是这样,我怀疑您可能必须自己将它们“组合在一起”。
回答by Jon Trauntvein
I use the following command line to build both the statically linked as well as the dynamically linked versions of boost:
我使用以下命令行来构建静态链接和动态链接的 boost 版本:
bjam "-sBUILD=debug release <runtime-link>static/dynamic <threading>multi" stage
This is done with visual c++ on windows YMMV.
这是在 Windows YMMV 上使用 Visual C++ 完成的。