我无法包含通过 vcpkg
安装的第 3 方库。
我正在使用
- Windows 10
- 安装了 C/C++、CMake 和 CMake 工具插件的 Visual Studio Code
- 用于获取 C++ 库的 VCPKG
- Cygwin g++ 编译器
- CMake
C:\Users\Jaiel>g++ --version
g++ (GCC) 10.2.0
C:\Users\Jaiel>vcpkg version
Vcpkg package management program version 2021-05-05-9f849c4c43e50d1b16186ae76681c27b0c1be9d9
C:\Users\Jaiel>cmake --version
cmake version 3.20.3
我试图完成一些测试项目来玩玩。
我尝试过:
- 休息
- wxwidgets
- sqlite3
都失败了。
下面我将概述我对 sqlite3 的尝试:
安装:
C:\Users\Jaiel>vcpkg install sqlite3
Computing installation plan...
The following packages will be built and installed:
sqlite3[core]:x86-windows -> 3.35.4#1
Detecting compiler hash for triplet x86-windows...
A suitable version of powershell-core was not found (required v7.1.0). Downloading portable powershell-core v7.1.0...
Downloading powershell-core...
https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/PowerShell-7.1.3-win-x86.zip -> C:\vcpkg\downloads\PowerShell-7.1.3-win-x86.zip
Extracting powershell-core...
A suitable version of 7zip was not found (required v18.1.0). Downloading portable 7zip v18.1.0...
Downloading 7zip...
https://www.nuget.org/api/v2/package/7-Zip.CommandLine/18.1.0 -> C:\vcpkg\downloads\7-zip.commandline.18.1.0.nupkg
Extracting 7zip...
A suitable version of nuget was not found (required v5.5.0). Downloading portable nuget v5.5.0...
Downloading nuget...
https://dist.nuget.org/win-x86-commandline/v5.5.1/nuget.exe -> C:\vcpkg\downloads\22ea847d-nuget.exe
Using cached binary package: C:\Users\Jaiel\AppData\Local\vcpkg\archives\65\6548fa5df73dbc6b768ef43fa0e5da4ca39334d4.zip
Starting package 1/1: sqlite3:x86-windows
Building package sqlite3[core]:x86-windows...
Building package sqlite3[core]:x86-windows... done
Installing package sqlite3[core]:x86-windows...
Installing package sqlite3[core]:x86-windows... done
Elapsed time for package sqlite3:x86-windows: 27.67 ms
Total elapsed time: 2.061 min
The package sqlite3:x86-windows provides CMake targets:
find_package(unofficial-sqlite3 CONFIG REQUIRED)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)
C:\Users\Jaiel>vcpkg integrate install
Applied user-wide integration for this vcpkg root.
All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
教程.cxx
#include <sqlite3.h>
#include <stdio.h>
int main()
{
printf("%s\n", sqlite3_libversion());
return 0;
}
CMakeLists.txt
# CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(test)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
add_executable(test tutorial.cxx)
target_link_libraries(test PRIVATE unofficial::sqlite3::sqlite3)
CMake 输出
[main] Building folder: test
[main] Configuring folder: test
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE:STRING=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=C:\cygwin64\bin\x86_64-pc-cygwin-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\cygwin64\bin\x86_64-pc-cygwin-g++.exe -Hc:/Users/Jaiel/Desktop/test -Bc:/Users/Jaiel/Desktop/test/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error at C:/vcpkg/scripts/buildsystems/vcpkg.cmake:772 (_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
[cmake]
[cmake] Add the installation prefix of "unofficial-sqlite3" to CMAKE_PREFIX_PATH or
[cmake] set "unofficial-sqlite3_DIR" to a directory containing one of the above
[cmake] files. If "unofficial-sqlite3" provides a separate development package or
[cmake] SDK, be sure it has been installed.
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:5 (find_package)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "C:/Users/Jaiel/Desktop/test/build/CMakeFiles/CMakeOutput.log".
它根本不适用于上述三个中的任何一个。 wxwidgets
给了我一个不同的错误,即缺少一些 LIBS 和 INCLUDE 路径,但无论我用 google 搜索多少,它都不起作用。
有人可以帮助我吗?
最佳答案
一个技巧是确保在安装 x64 vcpkg 依赖项时使用 x64-windows 调用 cmake。
x86-windows 的想法相同。
关于c++ - 无法使用 cmake + vcpkg 在 VS Code 中包含 C++ 项目的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67793665/