我使用vcpkg加载C++项目的C++。
对于vcpkg,
我想我把它整合得很正确:
PS D:\tool\vcpkg\vcpkg> .\vcpkg.exe 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=D:/tool/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake"例如,我安装了sqlite3:
PS D:\tool\vcpkg\vcpkg> vcpkg install sqlite3
Computing installation plan...
The following packages will be built and installed:
sqlite3[core]:x86-windows -> 3.37.2#1
Detecting compiler hash for triplet x86-windows...
-- Automatically setting HTTP(S)_PROXY environment variables to 127.0.0.1:7890
Restored 1 packages from C:\Users\shen\AppData\Local\vcpkg\archives in 168.6 ms. Use --debug to see more details.
Starting package 1/1: sqlite3:x86-windows
Installing package sqlite3[core]:x86-windows...
Elapsed time for package sqlite3:x86-windows: 33.18 ms
Total elapsed time: 5.525 s
The package sqlite3 provides CMake targets:
find_package(unofficial-sqlite3 CONFIG REQUIRED)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)关于架构,我的计算机是英特尔核心i5-9300H,它是x64,windows。但为了安全起见,我安装了所有的windows架构版本,如下所示:
PS D:\tool\vcpkg\vcpkg> vcpkg list
jsoncpp:x86-windows 1.9.5 jsoncpp is an implementation of a JSON reader an...
sqlite3:x64-windows 3.37.2#1 SQLite is a software library that implements a s...
sqlite3:x64-windows-static 3.37.2#1 SQLite is a software library that implements a s...
sqlite3:x86-windows 3.37.2#1 SQLite is a software library that implements a s...
sqlite3:x86-windows-static 3.37.2#1 SQLite is a software library that implements a s...
vcpkg-cmake-config:x64-windows 2022-02-06
vcpkg-cmake:x64-windows 2022-04-07对于C++项目,我尝试了qtcreater(cmake),visual studio
1,具有CMAKE的q创建器
cmakelist.txt
SET(DCMAKE_TOOLCHAIN_FILE "D:/tool/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake")
include("D:/tool/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake")
if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "" FORCE)
endif()
...
find_package(unofficial-sqlite3 CONFIG REQUIRED)它告诉我:
D:\tool\vcpkg\vcpkg\scripts\buildsystems\vcpkg.cmake:816: error: Could not find a package configuration file provided by "unofficial-sqlite3" with any of the following names: unofficial-sqlite3Config.cmake unofficial-sqlite3-config.cmake Add the installation prefix of "unofficial-sqlite3" to CMAKE_PREFIX_PATH or set "unofficial-sqlite3_DIR" to a directory containing one of the above files. If "unofficial-sqlite3" provides a separate development package or SDK, be sure it has been installed. CMakeLists.txt:23 (find_package)
:-1: error: [Makefile:249: cmake_check_build_system] Error 1我的完整CMakeLists.txt是:
cmake_minimum_required(VERSION 3.5)
SET(CMAKE_TOOLCHAIN_FILE "D:/tool/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake")
include("D:/tool/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake")
if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "" FORCE)
endif()
project(untitled VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(untitled
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET untitled APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(untitled SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(untitled
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(untitled PRIVATE Qt${QT_VERSION_MAJOR}::Widgets sqlite3)
set_target_properties(untitled PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(untitled)
endif()以上大部分都是由by创建者生成的。
当我这样做,并被这些错误,我想,它可能是由maybe创建者造成的。
所以我尝试使用visual studio 2019
视听演播室2019
在cmakelist.txt中,我添加了以下内容:
SET(DCMAKE_TOOLCHAIN_FILE "D:/tool/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake")
include("D:/tool/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake")
find_package(unofficial-sqlite3 CONFIG REQUIRED)它告诉我同样的错误:
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 CMake Error at D:/tool/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake:816 (_find_package):
Could not find a package configuration file provided by
"unofficial-sqlite3" with any of the following names:
unofficial-sqlite3Config.cmake
unofficial-sqlite3-config.cmake
Add the installation prefix of "unofficial-sqlite3" to CMAKE_PREFIX_PATH or
set "unofficial-sqlite3_DIR" to a directory containing one of the above
files. If "unofficial-sqlite3" provides a separate development package or
SDK, be sure it has been installed. D:/tool/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake 816 任何人都可以告诉我,我如何正确地使用sqlite3?
有关
CMAKE_TOOLCHAIN...和'DMAKE_TOOLCHAIN...`;我尝试过,甚至两者都尝试过,但结果是一样的。关于删除include(.../vcpkg.cmake)的QwQ;我看到了一个博客,它说我们需要添加这一行。但是我仍然尝试删除它,并重新配置,然后,我得到了同样的错误。
D:\tool\vcpkg\vcpkg\scripts\buildsystems\vcpkg.cmake:816: error: Could not find a package configuration file provided by "unofficial-sqlite3" with any of the following names: unofficial-sqlite3Config.cmake unofficial-sqlite3-config.cmake Add the installation prefix of "unofficial-sqlite3" to CMAKE_PREFIX_PATH or set "unofficial-sqlite3_DIR" to a directory containing one of the above files. If "unofficial-sqlite3" provides a separate development package or SDK, be sure it has been installed. CMakeLists.txt:23 (find_package)该错误链接到vcpkg.cmake:
elseif("${z_vcpkg_find_package_lowercase_package_name}" STREQUAL "grpc" AND EXISTS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/grpc")
_find_package(gRPC ${z_vcpkg_find_package_ARGN})
else()
_find_package("${z_vcpkg_find_package_package_name}" ${z_vcpkg_find_package_ARGN}) <---- this line
endif()发布于 2022-04-26 10:26:41
考虑使用:
find_package(SQLite3 REQUIRED)
target_link_libraries(untitled PRIVATE SQLite::SQLite3)内置CMake模块应该按照预期使用vcpkg。
还要确保VCPKG_TARGET_TRIPLET不是空的。
此外,清理您的cmake缓存。
https://stackoverflow.com/questions/71891210
复制相似问题