Detailed introduction to the compilation of boost 64-bit and 32-bit libraries under windows

黄舟
Release: 2017-06-07 09:31:35
Original
5629 people have browsed it

Common compilation commands:

cd E:\OpenSource\boost_1_63_0\boost_1_63_0
Copy after login

Compile 32-bit library:

To compile in x86 environment, you must first start Visual from the start menu Studio's Visual Studio 2008 Command Prompt to enter the command prompt

Run bootstrap.bat to generate the x86 version of bjam.exe

bjam toolset=msvc-9.0 threading=multi link=static runtime-link=static --with-regex
Copy after login

Compile 64-bit library:

To compile in x64 environment, you must first start Visual from the start menu Studio's Visual Studio 2008 x64 Win64 Command Prompt enters the command prompt

Run bootstrap.bat to generate the x64 version of bjam.exe

bjam toolset=msvc-9.0 threading=multi link=static runtime-link=static --with-regex address-model=64
Copy after login

Among them, --prefix sets the boost installation directory;

stage means only generating library files (dll and lib files);

toolset specifies the compiler, vs2010 is msvc-10.0, vs2005/vs2008 is msvc-8.0 and msvc-9.0 respectively;

variant determines which version to compile debug and release;

link determines whether to use a static library or a dynamic library, shared It is a dynamic library, static is a static library;

address-model determines the address length, that is, 32 or 64-bit program;

threading determines whether to use a single-threaded (single) or multi-threaded (multi) library ;

runtime-link determines whether to link the C/C++ standard library statically or dynamically (shared);

-s ICU_PATH sets the path of icu4c;

install will Generate include directory containing header files.

Theoretically, this article is applicable to various versions of boost, especially the latest version 1.48.0; applicable to various C++ compilers, such as VC6.0 (some libraries are not supported), VS2003, VS2005, VS2008, VS2010, V2012, gcc, arm-linux-gcc, C++ Builder etc.

First summarize the Windows system.

1. Download

First, download the latest version of the boost installation package from the boost official homepage, or use Subversion to obtain the latest version. The address is: http://svn.boost.org/svn/boost/ trunk. I usually use svn now, which makes it easy to update and build, instead of downloading a new installation package and rebuilding every time.

2. Installation

If you are using the downloaded installation package, please unzip the boost installation package to a local directory, such as: E:\SDK\boost; if you are using svn, also You can checkout the boost code to this directory. Because some boost classes need to be compiled into libraries before they can be used, we also need to prepare the boost-specific compilation auxiliary tool bjam. Execute bootstrap.bat in the root directory in the command prompt (cmd.exe), and the compiled bjam.exe will be automatically copied to the directory (bjam must be in the same directory as boost-build.jam).

3. Compilation

The next step is the most important compilation step. You need to open the command prompt (cmd.exe) window and execute bjam. You can use the --help parameter to view command help. Here is a detailed explanation of bjam's command line parameters, because it is very important. First of all, it involves the establishment of a programming environment, and you need to choose appropriate command line parameters according to your specific future use environment; secondly, it affects your hard disk space, which is said to be more than 3G if fully compiled.

The bjam command used is as follows:

bjam stage --toolset=msvc-9.0 --without-graph
 --without-graph_parallel --without-math --without-mpi --without-python --without-serialization --without-wave --stagedir="E:\SDK\boost\bin\vc9" 
link=static runtime-link=shared runtime-link=static threading=multi debug release
Copy after login

The meaning of each parameter is explained in detail below:

stage/installstage means that only libraries (dll and lib) are generated. Install will also generate the include directory containing header files. I recommend using stage, because the include directory generated by install is actually the boost directory after the boost installation package is decompressed (E:\SDK\boost\boost, which only has a few more non-hpp files than the include directory, and they are all very small), so It can be used directly, and different IDEs can use the same set of header files, which saves compilation time and hard disk space.

toolset:Specify the compiler, optional such as borland, gcc, msvc (VC6), msvc-9.0 (VS2008), etc.

without/with: Choose which libraries not to compile/compile. Because I don't need python, mpi and other libraries, I exclude them. There are also static libs compiled by libraries such as wave, graph, math, regex, test, program_options, serialization, and signals. They are all very large, so you can leave them out if they are not needed. This can be selected according to individual needs, and the default is to compile all. However, it should be noted that if you choose to compile python, you need python language support. You should download and install it from the official python homepage. The command to view boost included libraries is bjam --show-libraries.

stagedir/prefix: Use stagedir when stage, use prefix when installing, indicating the path of the compiled file. It is recommended to specify different directories for different IDEs. For example, VS2008 corresponds to E:\SDK\boost\bin\vc9, and VC6 corresponds to E:\SDK\boost\bin\vc6. Otherwise, they are all generated under one directory, making it difficult to manage. If the install parameter is used, the header file directory will also be generated. The corresponding directory for vc9 is E:\SDK\boost\bin\vc9\include\boost-1_46\boost, which is similar for vc6 (this path alone is so cumbersome, so use stage good).

build-dir编译生成的中间文件的路径。这个本人这里没用到,默认就在根目录(E:\SDK\boost)下,目录名为bin.v2,等编译完成后可将这个目录全部删除(没用了),所以不需要去设置。

link生成动态链接库/静态链接库。生成动态链接库需使用shared方式,生成静态链接库需使用static方式。一般boost库可能都是以static方式编译,因为最终发布程序带着boost的dll感觉会比较累赘。

runtime-link动态/静态链接C/C++运行时库。同样有shared和static两种方式,这样runtime-link和link一共可以产生4种组合方式,各人可以根据自己的需要选择编译。一般link只选static的话,只需要编译2种组合即可,即link=static runtime-link=shared和link=static runtime-link=static,本人一般就编这两种组合。

threading单/多线程编译。一般都写多线程程序,当然要指定multi方式了;如果需要编写单线程程序,那么还需要编译单线程库,可以使用single方式。

debug/release编译debug/release版本。一般都是程序的debug版本对应库的debug版本,所以两个都编译。

本人按以上方式分别编译了静态链接和动态链接两个版本后,整个E:\SDK\boost目录有1.28G。如果不打算将来再升级boost版本,那么可以将编译生成的中间文件bin.v2目录删除,这样整个目录(包括安装包解压缩文件和编译生成的库文件)会减小至不到800MB,如果runtime-link只选了一种方式,那么整个目录只有600MB。事实上编译完成后除了boost和bin目录之外其他目录和文件已经可以删除了,这样还可以腾出350MB的空间来。不过我又研究了一下,其实libs这个目录也很有用,它提供了所有Boost类的使用范例,平时可以作为参考;另外doc目录是一个完整的boost使用帮助文档,当然最好也不要删了。其他几个目录和文件加起来也就几十兆,索性都给它们留一条生路吧。

64 位编译

和32位环境不同,x64环境下编译得先从开始菜单启动Visual Studio的Visual Studio 2008 x64 Win64 Command Prompt进入命令提示符,而不是随便打开任意一个命令行窗口就行。然后转到boost根文件夹,运行bootstrap.bat生成x64版的bjam.exe。然后运行命令:

bjam --build-type=complete toolset=msvc-9.0 threading=multi link=shared address-model=64
Copy after login

即可生成DLL版平台库,如果要编译静态库版就把shared改为static。

  • 只生成一个库的话加上例如--with-python得编译选项,避免生成东西太多、时间太长。

  • 要有address-model=64属性,如果没有这个属性的话,会默认生成32位的平台库,加入这个选项才能生成64位的DLL。

  • 如果要生成Boost.Python库,需要先下载安装x64版的Python安装包,我用的版本是3.2.3。在使用这个库编写Python扩展DLL时,默认是使用动态库版的Boost.Python,要使用静态版的必须在C++项目中定义BOOST_PYTHON_STATIC_LIB宏,这样就不用在使用或发布扩展时带着boost_python-vc90-mt-1_50.dll一起了,当然扩展DLL的尺寸会大些,如果做实验没必要这样,编译又慢生成的文件也大。

The above is the detailed content of Detailed introduction to the compilation of boost 64-bit and 32-bit libraries under windows. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template