首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在VS代码中不能包含用于C++项目的libs和cmake + vcpkg

在VS代码中不能包含用于C++项目的libs和cmake + vcpkg
EN

Stack Overflow用户
提问于 2021-06-01 17:41:58
回答 1查看 764关注 0票数 1

我不能包括通过vcpkg安装的第三方库。

我在用

使用C/C++、CMake和CMake工具插件的

10

  • Visual Studio代码

代码语言:javascript
复制
C:\Users\Jaiel>g++ --version
g++ (GCC) 10.2.0
代码语言:javascript
复制
C:\Users\Jaiel>vcpkg version
Vcpkg package management program version 2021-05-05-9f849c4c43e50d1b16186ae76681c27b0c1be9d9
代码语言:javascript
复制
C:\Users\Jaiel>cmake --version
cmake version 3.20.3

我在试着做些测试项目来做游戏。

我试过:

  • restinio
  • wxwidgets
  • sqlite3

都失败了。

下面我将概述一下我对sqlite3的尝试:

Installation

代码语言:javascript
复制
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"

tutorial.cxx

代码语言:javascript
复制
#include <sqlite3.h>
#include <stdio.h>

int main()
{
    printf("%s\n", sqlite3_libversion());
    return 0;
}

CMakeLists.txt

代码语言:javascript
复制
# 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输出

代码语言:javascript
复制
[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和包含路径,但无论如何,它没有工作,无论我谷歌多少。

有人能帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2022-11-05 07:01:54

提示之一是确保在安装x64 vcpkg依赖项时使用x64-windows调用cmake。

x86-windows的想法也是一样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67793665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档