'how can I use vcpkg to install sqlite3 and use in cmakelist.txt?
I use vcpkg to load sqlite3 for my C++ project.
for vcpkg,
I think I integrate it correctly:
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"
and I install sqlite3 for example:
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)
about the architecture my computer is intel core i5-9300H, and it is x64, windows. but to be on the safe side, i installed all windows architeture version,like this:
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
for C++ project, I tried by qtcreater(cmake), visual studio
1,qtcreator with CMAKE
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)
and it told me:
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
my full CMakeLists.txt
is:
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()
most of above is generated by qtcreator
when I do those above, and stucked by these errors, I think, maybe it is caused by myqtcreator
so I tried with visual studio 2019
visual studio 2019
in cmakelist.txt i added those :
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)
and it told me the same error:
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 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
anyone can told me, how can I use the sqlite3 correctly?
about
CMAKE_TOOLCHAIN...
and 'DMAKE_TOOLCHAIN...`; any of them I have tried, and even both, but the result is the same. QwQ
about remove
include(.../vcpkg.cmake)
; i have saw a blog,and it says we need to add this line. but i still try to delete it,and reconfigure, and then, I got the same error
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)
and the error is linked to 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()
Solution 1:[1]
Consider using:
find_package(SQLite3 REQUIRED)
target_link_libraries(untitled PRIVATE SQLite::SQLite3)
inbuild CMake modules should work as expected using vcpkg.
Also make sure that VCPKG_TARGET_TRIPLET
is not empty
Furthermore clean your cmake cache.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alexander Neumann |