Issue
I use vcpkg and cmake to do some cross-platform devlpment. After finishing an sample code at WSL,I tried to change my toolchain to arm-linux-gnueabihf,then it shows below.
[cmake] Could not find a configuration file for package "plog" that is compatible
[cmake] with requested version "".
[cmake]
[cmake] The following configuration files were considered but not accepted:
[cmake]
[cmake] /home/fuxiaoer/vcpkg/installed/x64-linux/share/plog/plogConfig.cmake, version: 1.1.9 (64bit)
[cmake]
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:11 (find_package)
[cmake]
where plog
is a lib I try to use in this project.
then I remove plog:x64-linux.rebuild my project.it shows:
Could not find a package configuration file provided by "plog" with any of
[cmake] the following names:
[cmake]
[cmake] plogConfig.cmake
[cmake] plog-config.cmake
I tred to wriet an arm-linux-gnueabihf.cmake file for vcpkg at [vcpkgroot]/triplets/arm-linux-gnueabihf.cmake.
set(VCPKG_TARGET_ARCHITECTURE arm)
set(VCPKG_CMAKE_SYSTEM_NAME Linux)
set(VCPKG_CMAKE_SYSTEM_PROCESSOR arm)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
then use vcpkg install plog:arm-linux-gnueabihf
to install a new lib which use arm-linux-gnueabihf to build and it worked.
where /vcpkg/installed
shows 3 folders
arm-linux-gnueabihf vcpkg x64-linux
When turn around to my cmake project,it shows same message like I mentioned before.it seems like cmake do not change its search path,and still use default path x64-linux to find
I added a new line at my cmakelists.txt to tell cmake where plog is.
set(plog_DIR "/home/fuxiaoer/vcpkg/installed/arm-linux-gnueabihf/share/plog")
then this project finally can build successfuly.that means the method I use worked.
my CMakeLists.txt is shown below.
cmake_minimum_required(VERSION 3.0.0)
project(cmake_with_ninja_and_vcpkg VERSION 0.1.0 LANGUAGES C CXX)
include(CTest)
enable_testing()
# set(plog_DIR "/home/fuxiaoer/vcpkg/installed/arm-linux-gnueabihf/share/plog")
find_package(Eigen3 CONFIG REQUIRED)
find_package(plog CONFIG REQUIRED)
add_executable(cmake_with_ninja_and_vcpkg main.cpp)
target_link_libraries(cmake_with_ninja_and_vcpkg PRIVATE Eigen3::Eigen)
target_link_libraries(cmake_with_ninja_and_vcpkg PRIVATE plog::plog)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
Solution
I tried to change my toolchain to arm-linux-gnueabihf
changing toolchains simply requires a clean reconfigure (meaning using a fresh folder or deleting the CMakeCache.txt). You cannot change vcpkg triplets without that.
it seems like cmake do not change its search path,and still use default path x64-linux to find
that is exactly what happens if you try to switch in an already configured project or forget to set VCPKG_TARGET_TRIPLET
to the triplet you actually want to use. You might want to also set VCPKG_HOST_TRIPLET
. Don't forget this needs to be defined before project()
Answered By - Alexander Neumann Answer Checked By - Cary Denson (WPSolving Admin)