代码先锋网 代码片段及技术文章聚合

Visual Studio 2019安装boost 1.7.0库

技术标签: C/C++  Windows  visual studio  microsoft  windows

小结

在Visual Studio 2019使用了boost 1.7.0库,经过编译boost 1.7.0库,再添加配置到VS 2019工程中,进行了成功地测试。

问题

找不到boost的源文件

如果没有安装boost库,会在Visual Studio 2019的工程编译过程中找不到相应的源文件。
参见C++ problem: boost/asio.hpp non existing

boost库的版本问题

如果boost库的安装版本不对的话,会返回类似c2664 cannot convert executor to any_io_executor &的错误,参见Compiler Error C2664 , 这里我的情况是安装的boost库过高,安装了boost 1.7.9的库,原因不确定,但是安装低一点的版本boost 1.7.0库,这个问题就没有了。

也有安装的版本过低的情况,也是有问题。返回类似LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc141-mt-gd-x32-1_66.lib'的问题。

参见:
fatal error LNK1104: cannot open file ‘libboost_system-vc110-mt-gd-1_51.lib’

boost 1.7.0库的安装

参见https://www.boost.org/users/history/version_1_70_0.html,下载boost 1.7.0库Windows Zip文件,解压缩。

参见fatal error LNK1104: cannot open file 'libboost_system-vc110-mt-gd-1_51.lib’的过程进行安装。

首先需要执行以下VsDevCmd.bat指令,启动Visual Studio 2019 Developer Command Prompt v16.11.17

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools>VsDevCmd.bat
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.11.17
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************

否则会出现以下错误,
'cl' is not recognized as an internal or external command, operable program or batch file
和以下错误:
fatal error C1034: ctype.h: no include path set

参考Building Boost.Build engine ‘cl’ is not recognized as an internal or external command, operable program or batch file
how to install boost correctly
Error “fatal error C1034: windows.h: no include path set”

再执行bootstrap.bat

C:\boost_1_70_0>bootstrap.bat
Building Boost.Build engine

Generating Boost.Build configuration in project-config.jam for msvc...

Bootstrapping is done. To build, run:

    .\b2

To adjust configuration, edit 'project-config.jam'.
Further information:

    - Command line help:
    .\b2 --help

    - Getting started guide:
    http://boost.org/more/getting_started/windows.html

    - Boost.Build documentation:
    http://www.boost.org/build/

接着执行b2,生成library文件:

C:\boost_1_70_0>.\b2
Performing configuration checks

    - default address-model    : 32-bit
    - default architecture     : x86

Building the Boost C++ Libraries.


    - C++11 mutex              : yes
    - Boost.Config Feature Check: cxx11_auto_declarations : yes
    - Boost.Config Feature Check: cxx11_constexpr : yes
    - Boost.Config Feature Check: cxx11_defaulted_functions : yes
    - Boost.Config Feature Check: cxx11_final : yes
    - Boost.Config Feature Check: cxx11_hdr_mutex : yes
    - Boost.Config Feature Check: cxx11_hdr_tuple : yes
    - Boost.Config Feature Check: cxx11_lambdas : yes
    - Boost.Config Feature Check: cxx11_noexcept : yes
    - Boost.Config Feature Check: cxx11_nullptr : yes
    - Boost.Config Feature Check: cxx11_rvalue_references : yes
    - Boost.Config Feature Check: cxx11_template_aliases : yes
    - Boost.Config Feature Check: cxx11_thread_local : yes
    - Boost.Config Feature Check: cxx11_variadic_templates : yes
    - has_icu builds           : no
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
    - zlib                     : no
    - bzip2                    : no
    - lzma                     : no
    - zstd                     : no
    - iconv (libc)             : no
    - iconv (separate)         : no
    - icu                      : no
    - icu (lib64)              : no
    - native-atomic-int32-supported : yes
    - message-compiler         : yes
    - native-syslog-supported  : no
    - pthread-supports-robust-mutexes : no
    - compiler-supports-ssse3  : yes
    - compiler-supports-avx2   : yes
    - gcc visibility           : no
    - long double support      : yes
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
    - libbacktrace builds      : no
    - addr2line builds         : no
    - WinDbg builds            : yes
    - WinDbgCached builds      : yes
    - BOOST_COMP_GNUC >= 4.3.0 : no
    - zlib                     : no  (cached)
    - bzip2                    : no  (cached)
    - lzma                     : no  (cached)
    - zstd                     : no  (cached)
    - C++11 mutex              : yes
    - Boost.Config Feature Check: cxx11_auto_declarations : yes
    - Boost.Config Feature Check: cxx11_constexpr : yes
    - Boost.Config Feature Check: cxx11_defaulted_functions : yes
    - Boost.Config Feature Check: cxx11_final : yes
    - Boost.Config Feature Check: cxx11_hdr_mutex : yes
    - Boost.Config Feature Check: cxx11_hdr_tuple : yes
    - Boost.Config Feature Check: cxx11_lambdas : yes
    - Boost.Config Feature Check: cxx11_noexcept : yes
    - Boost.Config Feature Check: cxx11_nullptr : yes
    - Boost.Config Feature Check: cxx11_rvalue_references : yes
    - Boost.Config Feature Check: cxx11_template_aliases : yes
    - Boost.Config Feature Check: cxx11_thread_local : yes
    - Boost.Config Feature Check: cxx11_variadic_templates : yes
    - has_icu builds           : no
    - zlib                     : no
    - bzip2                    : no
    - lzma                     : no
    - zstd                     : no
    - iconv (libc)             : no
    - iconv (separate)         : no
    - icu                      : no
    - icu (lib64)              : no
    - native-atomic-int32-supported : yes
    - message-compiler         : yes
    - native-syslog-supported  : no
    - pthread-supports-robust-mutexes : no
    - compiler-supports-ssse3  : yes
    - compiler-supports-avx2   : yes
    - gcc visibility           : no
    - long double support      : yes
    - libbacktrace builds      : no
    - addr2line builds         : no
    - WinDbg builds            : yes
    - WinDbgCached builds      : yes
    - BOOST_COMP_GNUC >= 4.3.0 : no
    - zlib                     : no  (cached)
    - bzip2                    : no  (cached)
    - lzma                     : no  (cached)
    - zstd                     : no  (cached)

Component configuration:

    - atomic                   : building
    - chrono                   : building
    - container                : building
    - context                  : building
    - contract                 : building
    - coroutine                : building
    - date_time                : building
    - exception                : building
    - fiber                    : building
    - filesystem               : building
    - graph                    : building
    - graph_parallel           : building
    - headers                  : building
    - iostreams                : building
    - locale                   : building
    - log                      : building
    - math                     : building
    - mpi                      : building
    - program_options          : building
    - python                   : building
    - random                   : building
    - regex                    : building
    - serialization            : building
    - stacktrace               : building
    - system                   : building
    - test                     : building
    - thread                   : building
    - timer                    : building
    - type_erasure             : building
    - wave                     : building

...patience...
...patience...
...patience...
...patience...
...patience...
...found 26874 targets...
...updating 2407 targets...
compile-c-c++ bin.v2\libs\python\build\msvc-14.2\debug\link-static\python-3.7\threading-multi\list.obj
list.cpp
...
...
...
中间过程省略,赶时间比较久,大概要半个小时。。。
...
...
...updated 2407 targets...


The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    C:\boost_1_70_0

The following directory should be added to linker library paths:

    C:\boost_1_70_0\stage\lib


接着执行bjam.exe

C:\boost_1_70_0>bjam.exe
Performing configuration checks

    - default address-model    : 32-bit (cached)
    - default architecture     : x86 (cached)

Building the Boost C++ Libraries.


    - C++11 mutex              : yes (cached)
    - Boost.Config Feature Check: cxx11_auto_declarations : yes (cached)
    - Boost.Config Feature Check: cxx11_constexpr : yes (cached)
    - Boost.Config Feature Check: cxx11_defaulted_functions : yes (cached)
    - Boost.Config Feature Check: cxx11_final : yes (cached)
    - Boost.Config Feature Check: cxx11_hdr_mutex : yes (cached)
    - Boost.Config Feature Check: cxx11_hdr_tuple : yes (cached)
    - Boost.Config Feature Check: cxx11_lambdas : yes (cached)
    - Boost.Config Feature Check: cxx11_noexcept : yes (cached)
    - Boost.Config Feature Check: cxx11_nullptr : yes (cached)
    - Boost.Config Feature Check: cxx11_rvalue_references : yes (cached)
    - Boost.Config Feature Check: cxx11_template_aliases : yes (cached)
    - Boost.Config Feature Check: cxx11_thread_local : yes (cached)
    - Boost.Config Feature Check: cxx11_variadic_templates : yes (cached)
    - has_icu builds           : no  (cached)
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
    - zlib                     : no  (cached)
    - bzip2                    : no  (cached)
    - lzma                     : no  (cached)
    - zstd                     : no  (cached)
    - iconv (libc)             : no  (cached)
    - iconv (separate)         : no  (cached)
    - icu                      : no  (cached)
    - icu (lib64)              : no  (cached)
    - native-atomic-int32-supported : yes (cached)
    - message-compiler         : yes (cached)
    - native-syslog-supported  : no  (cached)
    - pthread-supports-robust-mutexes : no  (cached)
    - compiler-supports-ssse3  : yes (cached)
    - compiler-supports-avx2   : yes (cached)
    - gcc visibility           : no  (cached)
    - long double support      : yes (cached)
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
    - libbacktrace builds      : no  (cached)
    - addr2line builds         : no  (cached)
    - WinDbg builds            : yes (cached)
    - WinDbgCached builds      : yes (cached)
    - BOOST_COMP_GNUC >= 4.3.0 : no  (cached)
    - zlib                     : no  (cached)
    - bzip2                    : no  (cached)
    - lzma                     : no  (cached)
    - zstd                     : no  (cached)
    - C++11 mutex              : yes (cached)
    - Boost.Config Feature Check: cxx11_auto_declarations : yes (cached)
    - Boost.Config Feature Check: cxx11_constexpr : yes (cached)
    - Boost.Config Feature Check: cxx11_defaulted_functions : yes (cached)
    - Boost.Config Feature Check: cxx11_final : yes (cached)
    - Boost.Config Feature Check: cxx11_hdr_mutex : yes (cached)
    - Boost.Config Feature Check: cxx11_hdr_tuple : yes (cached)
    - Boost.Config Feature Check: cxx11_lambdas : yes (cached)
    - Boost.Config Feature Check: cxx11_noexcept : yes (cached)
    - Boost.Config Feature Check: cxx11_nullptr : yes (cached)
    - Boost.Config Feature Check: cxx11_rvalue_references : yes (cached)
    - Boost.Config Feature Check: cxx11_template_aliases : yes (cached)
    - Boost.Config Feature Check: cxx11_thread_local : yes (cached)
    - Boost.Config Feature Check: cxx11_variadic_templates : yes (cached)
    - has_icu builds           : no  (cached)
    - zlib                     : no  (cached)
    - bzip2                    : no  (cached)
    - lzma                     : no  (cached)
    - zstd                     : no  (cached)
    - iconv (libc)             : no  (cached)
    - iconv (separate)         : no  (cached)
    - icu                      : no  (cached)
    - icu (lib64)              : no  (cached)
    - native-atomic-int32-supported : yes (cached)
    - message-compiler         : yes (cached)
    - native-syslog-supported  : no  (cached)
    - pthread-supports-robust-mutexes : no  (cached)
    - compiler-supports-ssse3  : yes (cached)
    - compiler-supports-avx2   : yes (cached)
    - gcc visibility           : no  (cached)
    - long double support      : yes (cached)
    - libbacktrace builds      : no  (cached)
    - addr2line builds         : no  (cached)
    - WinDbg builds            : yes (cached)
    - WinDbgCached builds      : yes (cached)
    - BOOST_COMP_GNUC >= 4.3.0 : no  (cached)
    - zlib                     : no  (cached)
    - bzip2                    : no  (cached)
    - lzma                     : no  (cached)
    - zstd                     : no  (cached)

Component configuration:

    - atomic                   : building
    - chrono                   : building
    - container                : building
    - context                  : building
    - contract                 : building
    - coroutine                : building
    - date_time                : building
    - exception                : building
    - fiber                    : building
    - filesystem               : building
    - graph                    : building
    - graph_parallel           : building
    - headers                  : building
    - iostreams                : building
    - locale                   : building
    - log                      : building
    - math                     : building
    - mpi                      : building
    - program_options          : building
    - python                   : building
    - random                   : building
    - regex                    : building
    - serialization            : building
    - stacktrace               : building
    - system                   : building
    - test                     : building
    - thread                   : building
    - timer                    : building
    - type_erasure             : building
    - wave                     : building

...patience...
...patience...
...patience...
...patience...
...patience...
...patience...
...found 27172 targets...


The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    C:\boost_1_70_0

The following directory should be added to linker library paths:

    C:\boost_1_70_0\stage\lib

需要添加C:\boost_1_70_0C:\boost_1_70_0\stage\lib到VS 2019工程文件中。

添加boost 1.7.0库到VS 2019工程

进行以下设置:

  • Configuration Properties > C/C++ > Precompiled Headers. 设置Not Using Precompiled Headers(不知道这个有没有用)

  • Set the “General > Platform Toolset” to Visual Studio 2019 (v142).

  • 设置"General > C Language Standard" to ISO C11 Standard (/std:c11) (不知道这个有没有用)

  • Include the path to the boost folder (e.g. C:\boost_1_70_0) and the path to the subfolder containing the binary files (e.g. C:\boost_1_70_0\stage\lib) in:“C\C++ > Additional Include Directory” and “Linker > Additional Library Directories”.

编译问题

参见Why does Visual Studio 2013 error on C4996?, 对于C4996的问题,进行以下设置解决:
Apparently new projects enable “SDK check” by default now, which treats these warnings as errors. To disable it, go to project properties -> Configuration Properties -> C/C++ -> General -> SDL checks -> No.

参考

vs2015 安装boost库
C++ problem: boost/asio.hpp non existing
https://www.boost.org/users/history/version_1_70_0.html
How to add boost library 1_65 or 1_64 to Visual Studio 2017 project?
Compiler Error C2664
Why does Visual Studio 2013 error on C4996?
Having problems with Boost library and Visual Studio (C++)
fatal error LNK1104: cannot open file ‘libboost_system-vc110-mt-gd-1_51.lib’
Building Boost.Build engine ‘cl’ is not recognized as an internal or external command, operable program or batch file
how to install boost correctly
Error “fatal error C1034: windows.h: no include path set”

版权声明:本文为scruffybear原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/scruffybear/article/details/126167484

智能推荐

Visual Studio Community 2019 问题

严重性 代码 说明 项目 文件 行 禁止显示状态 错误 C4996 ‘scanf’: This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for...

visual studio添加lib库

方法1: 通过设置工程配置来添加lib库. A、添加工程的头文件目录:工程---属性---配置属性---c/c++---常规---附加包含目录:加上头文件存放目录。 B、添加文件引用的lib静态库路径:工程---属性---配置属性---链接器---常规---附加库目录:加上lib文件存放目录。 C 然后添加工程引用的lib文件名:工程---属性---配置属性---链接器---输入---附加依赖项:...

Visual Studio引入NLPIR库

Visual Studio引入NLPIR库 作者版权:林子 Leoch007 欢迎转载,注明出处 工作环境:Win10,Visual Studio2017 NLPIR一款中文分词系统,前身是2000年发布的ICTCLAS词法分析系统,性能在同类中极为优秀,也支持二次开发。作者是张华平博士,Github地址为:https://github.com/NLPIR-team/NLPIR/tree/mast...

Visual Studio Code安装ESLint

安装 Visual Studio Code ESLint 插件 打开 Visual Studio Code ,首先使用快捷键 Ctrl + Shift + P 调出VsCode的控制台,然后输入下面的命令安装ESLint插件: 使用 NPM 安装 ESLint 为了方便我们通过ESLint命令行工具来帮助我们生成ESLint相关的配置,我...

Ubuntu安装Visual Studio Code

第一步——下载: 官网 https://code.visualstudio.com/docs/?dv=linux64_deb 第二步——安装: 安装成功,可将图标添加到桌面 #以下是一些 Dpkg 的普通用法: 转载于:https://www.jianshu.com/p/0e2f7ec8d82a...

猜你喜欢

Ubuntu 安装 Visual Studio Code

直接下载deb包安装失败,具体原因不明。通过官网提供的添加repository的方式安装成功: 之后, 就可以安装成功了。...

boost 1.35.0 Visual Studio 2008编译指南

一。下载 boost库2008年3月底发布了1.35.0版本,包括了12个新的库和若干对于新库的修正。请参见http://www.boost.org/users/news/version_1_35_0来获取详细的更新信息。 最大的喜讯就是提供了对于Visual Studio 2008编译器的支持(1.34也可以,但是需要手工修改)。 下载地址: http://www.boost.org/users...

如何Visual Studio环境使用 C++ Boost库,详细步骤

How to build the Boost Library (refer to the link: http://www.boost.org/doc/libs/1_60_0/more/getting_started/windows.html#header-only-libraries) 1. download the BOOST Lib from GitHub: https://github.c...

visual studio编译boost1.73.0静态库32位和64位

使用vs2015编译32位 使用vs2015编译64位 编译出的头文件: $(BOOST_SOURCE_DIR)/boost 在设置工程头文件路径设置为$(BOOST_SOURCE_DIR) 这样在C++代码中可以使用  #include <boost/...> 编译出来的库简要说明(库在$(BOOST_SOURCE_DIR)/vc14下的32位和64位文件夹中) b2.ex...