C++ Boost 库 - 只构建我需要的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4714289/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 16:15:57  来源:igfitidea点击:

Boost libraries - build only what I need

c++boost

提问by Till B

I downloaded the Boost libraries and now I want to build only a few of the libraries. What would be the right command for this? Apparently the built-type=complete option gives me too much. I am using Windows XP and want to use Bjam to compile Boost and MinGW to finally use it. At the moment I think I need the libraries Boost.filesystem, Boost.ProgramOptions and Boost.System. Another question: Where do I put the header-only libraries?

我下载了 Boost 库,现在我只想构建几个库。什么是正确的命令?显然,built-type=complete 选项给了我太多。我使用的是 Windows XP,想使用 Bjam 编译 Boost 和 MinGW 以最终使用它。目前我认为我需要 Boost.filesystem、Boost.ProgramOptions 和 Boost.System 库。另一个问题:我应该把头文件库放在哪里?

回答by Sam Miller

In step 5.2.4of Getting Startedyou can instruct b2which libraries to build:

入门的步骤 5.2.4 中,您可以指示要构建哪些库:b2

./b2 --with-program_options --with-filesystem --with-system

Alternatively, use ./b2 --show-librariesto see a list of all libraries that are not header-only.

或者,使用./b2 --show-libraries来查看所有不是仅标头的库的列表。

Following is an excerpt from the page:

以下是该页面的摘录:

In particular, to limit the amount of time spent building, you may be interested in:

  • reviewing the list of library names with --show-libraries
  • limiting which libraries get built with the --with-<library-name>or --without-<library-name>options
  • choosing a specific build variant by adding release or debug to the command line.

特别是,为了限制构建所花费的时间,您可能对以下内容感兴趣:

  • 查看库名称列表 --show-libraries
  • 限制使用--with-<library-name>--without-<library-name>选项构建哪些库
  • 通过向命令行添加发布或调试来选择特定的构建变体。

Note:b2command depends upon boost version so use following commands as per your boost version(Also, in this case use --with-libraries=<comma-seperated-library-names>version instead of --with-<library-name>):

注意:b2命令取决于 boost 版本,因此请根据您的 boost 版本使用以下命令(此外,在这种情况下,请使用--with-libraries=<comma-seperated-library-names>version 而不是--with-<library-name>):

  • ./configurefor 1.38.0and earlier
  • ./bootstrap.shfor 1.39.0onwards till 1.46.0
  • ./configure对于1.38.0和更早
  • ./bootstrap.sh对于1.39.0起直到1.46.0

回答by Cookie

These answers didn't work for me. On Windows, this worked for me:

这些答案对我不起作用。在 Windows 上,这对我有用:

b2.exe -with-LIBRARY

For example,

例如,

b2.exe -with-test

回答by Haiyang Xu

The BCPutility is a tool for extracting subsets of Boost. It's useful for Boost authors who want to distribute their library separately from Boost, and for Boost users who want to distribute a subset of Boost with their application.

BCP实用程序是用于提取的Boost子集的工具。对于想要与 Boost 分开分发他们的库的 Boost 作者,以及想要随他们的应用程序分发 Boost 子集的 Boost 用户来说,它非常有用。

The current version of Boost (1.50.0) uses Boost.Build. The new workflow for building BCP is as follows:

当前版本的 Boost (1.50.0) 使用 Boost.Build。新建 BCP 的工作流程如下:

From the root Boost directory, type:

在 Boost 根目录中,键入:

bootstrap.bat

Then, once Boost.Build has been built, type:

然后,一旦构建了 Boost.Build,输入:

b2 tools/bcp

To extract, for example interprocessonly, you could use:

要提取,例如interprocess,您可以使用:

$ mkdir /tmp/interprocess #bcp needs this
$ bcp interprocess /tmp/interprocess

This copies interprocess and its dependencies to /tmp/interprocess.

这会将进程间及其依赖项复制到/tmp/interprocess.

回答by Arun kumar Kalaiarasan

I had the same problem. But I found a way to create the necessary files.

我有同样的问题。但我找到了一种创建必要文件的方法。

Steps to follow:

要遵循的步骤:

  1. If you have Microsoft Visual Studio 2010 then open the Microsoft Visual Studio command prompt (2010) in administrator mode.
  2. First enter the code:

    bootstrap.bat
    
  3. Then enter the following code to generate lib files:

    b2.exe link=static runtime-link=static --with-chrono --with-date_time --with-filesystem --with-program_options --with-system --toolset=msvc-10.0 define=BOOST_USE_WINAPI_VERSION=0x0500
    
  4. Library files will be created in stage folder.

  1. 如果您有 Microsoft Visual Studio 2010,则在管理员模式下打开 Microsoft Visual Studio 命令提示符 (2010)。
  2. 首先输入代码:

    bootstrap.bat
    
  3. 然后输入以下代码生成lib文件:

    b2.exe link=static runtime-link=static --with-chrono --with-date_time --with-filesystem --with-program_options --with-system --toolset=msvc-10.0 define=BOOST_USE_WINAPI_VERSION=0x0500
    
  4. 库文件将在 stage 文件夹中创建。

回答by Andry

My last build attempt for the Boost 1.55 libraries was a dissappointment. All attempts to build several libraries and only them has ended up with total mess in output.

我对 Boost 1.55 库的最后一次构建尝试令人失望。构建多个库的所有尝试,只有它们最终导致输出完全混乱。

BJam either tries to build everything or build only the requested, but in the "bin.v2/[long-random-path]" folders (library per directory) with crap in them which is a headache to copy only the link libraries to somethere else.

BJam 要么尝试构建所有内容,要么仅构建请求的内容,但在“bin.v2/[long-random-path]”文件夹(每个目录的库)中包含垃圾内容,仅将链接库复制到某处是一件令人头疼的事别的。

I have accidentally found the right way to build-and-collect only the libraries I want in one place without any other crap:

我意外地找到了正确的方法,只在一个地方构建和收集我想要的库,而没有任何其他废话:

bjam ... --with-[library1] --with-[library2] stage

bjam ... --with-[library1] --with-[library2] 阶段

  • the "stage" option is required to build and collect libraries in one folder: /stage/lib
  • the "--with-[library]" option is required to build only the library you want.
  • 在一个文件夹中构建和收集库需要“stage”选项:/stage/lib
  • “--with-[library]”选项是只构建你想要的库所必需的。

回答by stanthomas

An additional note for anyone who sees the error message: "error: wrong library name '<name of library>' in the --with-<library> option.".

对于看到错误消息的任何人的附加说明: "error: wrong library name '<name of library>' in the --with-<library> option."

If you try to be clever, as I did, and only extract the boostsub-directory of the download onto your system to minimise space, b2will not be able to find the source code and build options for those libraries that are not header-only. I.e. you need the libsub-directory too (and tools).

如果您像我一样尝试聪明一点,并且只boost将下载的子目录解压缩到您的系统上以最小化空间,那么b2将无法找到那些不是仅包含头文件的库的源代码和构建选项。即您也需要lib子目录(和tools)。