我有一个使用boost和zmq库的基于cmake的C++项目。
我正在尝试使用Visual Studio Community 2017和vcpkg在Windows上构建它。
我按照项目页面上的说明安装了vcpkg。
现在,我可以看到已安装所需的软件包:
PS C:\Users\me\source\repos\vcpkg> .\vcpkg list
boost-accumulators:x64-windows 1.67.0 Boost accumulators module
boost-accumulators:x86-windows 1.67.0 Boost accumulators module
boost-algorithm:x64-windows 1.67.0 Boost algorithm module
boost-algorithm:x86-windows 1.67.0 Boost algorithm module
…
boost-variant:x64-windows 1.67.0 Boost variant module
boost-variant:x86-windows 1.67.0 Boost variant module
boost-vcpkg-helpers:x64-windows 4 a set of vcpkg-internal scripts used to modulari...
boost-vcpkg-helpers:x86-windows 4 a set of vcpkg-internal scripts used to modulari...
boost-vmd:x64-windows 1.67.0 Boost vmd module
boost-vmd:x86-windows 1.67.0 Boost vmd module
boost-wave:x64-windows 1.67.0 Boost wave module
boost-wave:x86-windows 1.67.0 Boost wave module
boost-winapi:x64-windows 1.67.0 Boost winapi module
boost-winapi:x86-windows 1.67.0 Boost winapi module
boost-xpressive:x64-windows 1.67.0 Boost xpressive module
boost-xpressive:x86-windows 1.67.0 Boost xpressive module
boost:x64-windows 1.67.0 Peer-reviewed portable C++ source libraries
boost:x86-windows 1.67.0 Peer-reviewed portable C++ source libraries
bzip2:x64-windows 1.0.6-2 High-quality data compressor.
bzip2:x86-windows 1.0.6-2 High-quality data compressor.
liblzma:x64-windows 5.2.3-2 Compression library with an API similar to that ...
liblzma:x86-windows 5.2.3-2 Compression library with an API similar to that ...
openssl:x64-windows 1.0.2o-3 OpenSSL is an open source project that provides ...
openssl:x86-windows 1.0.2o-3 OpenSSL is an open source project that provides ...
protobuf:x64-windows 3.5.1-5 Protocol Buffers - Google's data interchange format
protobuf:x86-windows 3.5.1-5 Protocol Buffers - Google's data interchange format
python3:x64-windows 3.6.4-2 The Python programming language as an embeddable...
python3:x86-windows 3.6.4-2 The Python programming language as an embeddable...
zeromq:x64-windows 2018-07-01 The ZeroMQ lightweight messaging kernel is a lib...
zeromq:x86-windows 2018-07-01 The ZeroMQ lightweight messaging kernel is a lib...
zlib:x64-windows 1.2.11-3 A compression library
zlib:x86-windows 1.2.11-3 A compression library
我还运行了
.\vcpkg integrate install
以启用集成:PS C:\Users\me\source\repos\vcpkg> .\vcpkg integrate install
Applied user-wide integration for this vcpkg root.
All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake"
接下来,Visual Studio能够立即打开CMake项目。我显然需要添加的唯一一件事是工具链文件。因此,我转到
CMakeLists.txt
->“更改CMake设置”,并为每个目标设置"cmakeCommandArgs": "-DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake"
(有4个目标,调试/发行版x x86/x64)。但是,正如我在Visual Studio的“输出” Pane 中看到的那样,一旦重新启动CMake,它仍然找不到依赖项:
1> Command line: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\me\CMakeBuilds\55e700de-d370-f634-bc40-455cedaf329e\install\x86-Debug" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe" -DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\me\Source\Repos\bluezero"
1> Working directory: C:\Users\me\CMakeBuilds\55e700de-d370-f634-bc40-455cedaf329e\build\x86-Debug
1> -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:2044 (message):
1> Unable to find the requested Boost libraries.
1>
1> Unable to find the Boost header files. Please set BOOST_ROOT to the root
1> directory containing Boost or BOOST_INCLUDEDIR to the directory containing
1> Boost's headers.
1> Call Stack (most recent call first):
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Error at C:\Users\me\Source\Repos\bluezero\CMakeLists.txt:46 (find_package):
1> Could not find a package configuration file provided by "ZeroMQ" with any
1> of the following names:
1>
1> ZeroMQConfig.cmake
1> zeromq-config.cmake
1>
1> Add the installation prefix of "ZeroMQ" to CMAKE_PREFIX_PATH or set
1> "ZeroMQ_DIR" to a directory containing one of the above files. If "ZeroMQ"
1> provides a separate development package or SDK, be sure it has been
1> installed.
1>
1>
1> -- Configuring incomplete, errors occurred!
1> See also "C:/Users/me/CMakeBuilds/55e700de-d370-f634-bc40-455cedaf329e/build/x86-Debug/CMakeFiles/CMakeOutput.log".
1> See also "C:/Users/me/CMakeBuilds/55e700de-d370-f634-bc40-455cedaf329e/build/x86-Debug/CMakeFiles/CMakeError.log".
1> C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\me\CMakeBuilds\55e700de-d370-f634-bc40-455cedaf329e\install\x86-Debug" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe" -DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\me\Source\Repos\bluezero" returned with exit code: 1
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:2044 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
CMakeLists.txt:44 (find_package)
CMake Error at CMakeLists.txt:46 (find_package):
Could not find a package configuration file provided by "ZeroMQ" with any
of the following names:
ZeroMQConfig.cmake
zeromq-config.cmake
Add the installation prefix of "ZeroMQ" to CMAKE_PREFIX_PATH or set
"ZeroMQ_DIR" to a directory containing one of the above files. If "ZeroMQ"
provides a separate development package or SDK, be sure it has been
installed.
特别是命令行:
确实包含
-DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake
,但显然这还不够。CMakeLists.txt
文件中有关查找依赖项的相关部分是:if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
add_definitions(-DBOOST_ALL_NO_LIB)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DBOOST_USE_WINDOWS_H)
add_definitions(-DNOMINMAX)
endif()
find_package(Doxygen)
find_package(Boost 1.54 REQUIRED COMPONENTS thread system regex timer filesystem serialization)
if(WIN32)
find_package(ZeroMQ CONFIG REQUIRED)
else()
find_package(ZMQ 4.1.4 REQUIRED)
endif()
find_package(ZLIB)
find_package(LZ4)
我在犯一些明显的错误吗?
最佳答案
我遇到了同样的问题,所以我切换到命令行使用vscode在Windows上运行项目,并且它可以完美运行.Visual Studio的问题是vcpkg安装了32位版本,而Visual Studio正在寻找x64版本的库,因此只需强制将vcpkg安装x64版本,例如以下示例:
vcpkg install <Your library>:x64-windows
您还可以使用以下命令通过命令行在Visual Studio代码中运行项目:
cmake . -GNinja -DCMAKE_TOOLCHAIN_FILE=<VCPKG installed folder>/vcpkg/scripts/buildsystems/vcpkg.cmake
在那之后运行:
ninja
然后运行您的项目。
由于此命令有效,但等效命令不适用于Visual Studio,因此我猜这是Visual Studio错误。
关于c++ - vcpkg + cmake + visual studio无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51476413/