c++ - 无法在 linux 上使用 vcpkg
问题描述
这是我的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)
我正在尝试通过 vcpkg 使用SET(CMAKE_TOOLCHAIN_FILE ${vcpkg_root})
,但似乎它不起作用。这是错误:
[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)
我通过安装 sqlite3vcpkg install 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 策略级别设置为完全古老的3.0 是否重要,或者您是否使用旧的 vcpkg 结帐(我在撰写本文时使用了最近的提交)。
推荐阅读
- java - 显示在另一个类/文件中创建的菜单栏
- javascript - 自定义 Wordpress 插件:无法读取 null 的属性“parentElement”
- bash - awk 将三列中的数字相加,只返回一列
- opengl - 使用 GL_SHADER_STORAGE_BUFFER 将数组传递给片段着色器
- java - Velocity 1.7 - 有时 Directive.postRender 在 Velocity.evaluate 中抛出 NullPointerException
- angular - 如何获取在角度 7 中选中的多个复选框的计数
- javascript - 为getelementbyid动态生成的HTML获取null
- javascript - Prisma 无法从另一个 docker 容器连接 localhost:4466
- mongodb - 如何制作与时间相关的 mongodb 视图管道?
- json - 将 instagram 位置 ID 转换为纬度和经度,以便我可以将它们覆盖在 Google 地图上