C++ 在windows上设置CMake和vcpkg时出错“无法打开包含文件”`
我一直试图遵循以下步骤,但我无法解决在最后一步中出现的构建错误:C++ 在windows上设置CMake和vcpkg时出错“无法打开包含文件”`,c++,sqlite,cmake,vcpkg,C++,Sqlite,Cmake,Vcpkg,我一直试图遵循以下步骤,但我无法解决在最后一步中出现的构建错误: fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory 我的vcpkg设置过程如下: >git克隆https://github.com/Microsoft/vcpkg.git >cd-vcpkg\ >\bootstrap-vcpgg.bat >vcpkg安装sqlite3:x64 windows >vcpkg集成安装
fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory
我的vcpkg设置过程如下:
>git克隆https://github.com/Microsoft/vcpkg.git
>cd-vcpkg\
>\bootstrap-vcpgg.bat
>vcpkg安装sqlite3:x64 windows
>vcpkg集成安装
我确认sqlite安装:
> vcpkg list
sqlite3:x64-windows 3.29.0-1 SQLite is a software library that implements a s...
我在测试repo中创建以下文件:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(test)
find_package(Sqlite3 REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main sqlite3)
main.cpp:
#include <sqlite3.h>
#include <stdio.h>
int main()
{
printf("%s\n", sqlite3_libversion());
return 0;
}
最后,我触发构建,但失败:
> cmake --build .
Microsoft (R) Build Engine version 16.3.1+1def00d3d for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Checking Build System
Building Custom Rule C:/Workspace/testCmake/CMakeLists.txt
main.cpp
C:\Workspace\testCmake\main.cpp(1,10): fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory [C:\Workspace\testCmake\build\main.vcxproj]
在提供SQLite3库以链接目标链接库时,需要让可执行文件知道头文件的位置。使用: 如果找到SQLite3,CMake将填充这些变量,看起来是这样的: SQLite3\u INCLUDE\u DIRS:在哪里可以找到SQLite3.h等。 SQLite3_库:链接以使用SQLite3的库。 SQLite3_版本:找到的SQLite3库的版本 SQLite3_找到:如果找到,则为TRUE
因此,如果对target_link_库的调用未按预期工作,请尝试使用${SQLite3_libraries}而不是SQLite3。在提供SQLite3库以链接到target_link_库时,需要让可执行文件知道头文件的位置。使用: 如果找到SQLite3,CMake将填充这些变量,看起来是这样的: SQLite3\u INCLUDE\u DIRS:在哪里可以找到SQLite3.h等。 SQLite3_库:链接以使用SQLite3的库。 SQLite3_版本:找到的SQLite3库的版本 SQLite3_找到:如果找到,则为TRUE
因此,如果您对target\u link\u库的调用没有按预期工作,请尝试使用${SQLite3\u libraries}而不是SQLite3。您已经结束了几个小时的挫折,谢谢!它与${SQLite3_LIBRARIES}一起工作。您结束了几个小时的沮丧,谢谢!它与${SQLite3_LIBRARIES}一起工作。
> cmake --build .
Microsoft (R) Build Engine version 16.3.1+1def00d3d for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Checking Build System
Building Custom Rule C:/Workspace/testCmake/CMakeLists.txt
main.cpp
C:\Workspace\testCmake\main.cpp(1,10): fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory [C:\Workspace\testCmake\build\main.vcxproj]
cmake_minimum_required(VERSION 3.0)
project(test)
find_package(Sqlite3 REQUIRED)
add_executable(main main.cpp)
# Add this line after the target is defined.
target_include_directories(main PRIVATE ${SQLite3_INCLUDE_DIRS})
target_link_libraries(main sqlite3)