0

I am building a demo cross-platform application (Windows + Raspberry Pi) in C++. I am using vcpkg package manager for libraries.
When I create project only for Windows (without cmake) things work perfectly.
I am now trying to build for Windows using cmake I am getting the bellow mentioned error for libraries installed via vcpkg package manager. I have confirmed that libraies are installed and are working properly when used with normal Windows console application.

During installation of vcpkg the following line was returned to enable vcpkg support in cmake.

"-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake"

Cmake FIle

# Set to C++20 standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_BUILD_TYPE debug)
# Set to C17 standard
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
# Set vcpkg library path
set(CMAKE_TOOLCHAIN_FILE C:/vcpkg/scripts/buildsystems/vcpkg.cmake)
# Add source to this project's executable.
add_executable (Test main.cpp)

if (CMAKE_VERSION VERSION_GREATER 3.12)
  set_property(TARGET Test PROPERTY CXX_STANDARD 20)
endif()

Error

fatal error C1083: Cannot open include file: 'boost/asio.hpp': No such file or directory
fatal error C1083: Cannot open include file: 'boost/asio.hpp': No such file or directory
fatal error C1083: Cannot open include file: 'mqtt/async_client.h': No such file or directory
fatal error C1083: Cannot open include file: 'plog/Log.h': No such file or directory
Dark Sorrow
  • 1,681
  • 14
  • 37
  • 1
    The examples in [Mastering CMake](https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html) set the cache variable via commandline. I believe the toolchain file needs to be set before the first `project()` call (citation needed). Are you doing that? Also: related: [CMake: specifying build toolchain](https://stackoverflow.com/q/5098360/11107541). – starball Nov 17 '22 at 02:44
  • 1
    1. As stated by the previous commenter, setting `CMAKE_TOOLCHAIN_FILE` after the `project()` call is wrong. The best place to specify a toolchain is a command line parameter, as vcpkg suggested you upon installation. 2. Setting vcpkg toolchain alone doesn't add all libraries to your project. It just allows you to use `find_package` for the libraries, installed in vcpkg. When you install a library in vcpkg, it usually shows you the possible `find_package` call. See e.g. [that question](https://stackoverflow.com/questions/73132267/how-to-import-library-in-cmake-download-by-vcpkg). – Tsyvarev Nov 17 '22 at 08:32

0 Answers0