报错为:
/opt/tiger/ide_deploy/.server/clion/clion/bin/cmake/linux/x64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/opt/tiger/ide_deploy/.server/clion/clion/bin/ninja/linux/x64/ninja -G Ninja -S /home/byteide/CLionProjects/just-test -B /home/byteide/CLionProjects/just-test/cmake-build-debug
CMake Error at CMakeLists.txt:9 (find_package):
Could not find a package configuration file provided by "nlohmann_json"
with any of the following names:
nlohmann_jsonConfig.cmake
nlohmann_json-config.cmake
Add the installation prefix of "nlohmann_json" to CMAKE_PREFIX_PATH or set
"nlohmann_json_DIR" to a directory containing one of the above files. If
"nlohmann_json" provides a separate development package or SDK, be sure it
has been installed.
-- Configuring incomplete, errors occurred!
[Finished]
cmake文件为
cmake_minimum_required(VERSION 3.27)
project(just_test)
set(CMAKE_CXX_STANDARD 20)
# 使用 vcpkg 集成
set(CMAKE_TOOLCHAIN_FILE "/home/byteide/vcpkg/scripts/buildsystems/vcpkg.cmake")
find_package(nlohmann_json CONFIG REQUIRED)
add_executable(just_test main.cpp
people/people.cpp
people/people.h)
target_link_libraries(just_test PRIVATE nlohmann_json::nlohmann_json)
解决方案:
CMAKE没有读取到vcpkg的安装目录,需要手动指定一下,在cmake文件中添加一行:
list(APPEND CMAKE_PREFIX_PATH "/home/byteide/vcpkg/installed/x64-linux")