无法在 linux 上使用 vcpkg

Can't use vcpkg on linux

这是我的 CMakelists.txt:

cmake_minimum_required(VERSION 3.0) 
SET(CMAKE_TOOLCHAIN_FILE "/home/xxx/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(test)

find_package(unofficial-sqlite3 CONFIG REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)

我正在尝试通过 SET(CMAKE_TOOLCHAIN_FILE ${vcpkg_root}) 使用 vcpkg,但似乎没有 work.Here 是错误:

[cmake] CMake Error at CMakeLists.txt:5 (find_package):
[cmake]   Could not find a package configuration file provided by
[cmake]   "unofficial-sqlite3" with any of the following names:
[cmake] 
[cmake]     unofficial-sqlite3Config.cmake
[cmake]     unofficial-sqlite3-config.cmake

我已确认 unofficial-sqlite3-config.cmake 确实存在于

/home/xxx/vcpkg/packages/sqlite3_x64-linux/share/unofficial-sqlite3/unofficial-sqlite3-config.cmake

我正在使用 WSL 和 vscode 作为 IDE,现在我不知道如何修复它。

我无法使用以下基本方法重现您的问题 CMakeLists.txt

cmake_minimum_required(VERSION 3.21)
project(test)

find_package(unofficial-sqlite3 REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)

我通过 vcpkg install sqlite3 安装了 sqlite3 并且 运行 通过

构建
$ echo 'int main() { return 0; }' > main.cpp
$ cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/build

如您所见,这完美无缺。我不确定是否将您的 CMake 策略级别设置为彻头彻尾的 ancient 3.0 是否重要,或者您是否使用旧的 vcpkg 检出(我在写作)。