vcpkg + cmake + visual studio not working
Asked Answered
G

1

10

I have a cmake-based C++ project using boost and zmq libraries.

I'm trying to build it on Windows using Visual Studio Community 2017 and vcpkg.

I installed vcpkg following the instructions on the project page.

Now I can see the required packages installed:

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

I also ran .\vcpkg integrate install to enable integration:

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"

Next, Visual Studio is able to open the CMake project right away. The only thing I need to add apparently is the toolchain file. So I go to CMakeLists.txt -> "Change CMake settings", and set "cmakeCommandArgs": "-DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake" for every target (there are 4 targets, debug/release x x86/x64).

But as soon as CMake is restarted, as I see in the Visual Studio's "Output" pane, still it can't find the dependencies:

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.

In particular, the command line:

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"

does contain the -DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake as it should be, but apparently this is not enough.

The relevant section of the CMakeLists.txt file about finding dependencies is:

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)

Am I making some obvious mistake?

Gestate answered 23/7, 2018 at 10:16 Comment(1)
The following answer solved this for me: https://mcmap.net/q/159271/-how-to-link-c-program-with-boost-using-cmakeBioplasm
F
1

I had same issue so I switched to command line for running project on windows with vscode and it runs perfectly.Issue for visual studio is that vcpkg install 32bit version and visual studio is looking for x64 version of library, So simply force it vcpkg to install x64 version instead like following example:

vcpkg install <Your library>:x64-windows

You can also run your project in visual studio code with the command line using the following commands:

cmake . -GNinja -DCMAKE_TOOLCHAIN_FILE=<VCPKG installed folder>/vcpkg/scripts/buildsystems/vcpkg.cmake

After that run:

ninja

And then run your project. Because this command works but its equivalent does not work on visual studio, I guess it's visual studio bug.

Footpound answered 21/3, 2020 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.