在Windows“无法打开包含文件”上设置CMake和vcpkg时出错

瑞安·内尔(Ryan Nel)

我一直在尝试遵循vcpkg设置指南,但无法解决在最后一步中遇到的生成错误:

fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory

我的vcpkg设置过程如下:

  • > git clone https://github.com/Microsoft/vcpkg.git
  • > cd vcpkg\
  • > .\bootstrap-vcpkg.bat
  • > vcpkg install sqlite3:x64-windows
  • > vcpkg integrate install

我确认安装了sqlite:

> vcpkg list

sqlite3:x64-windows                 3.29.0-1         SQLite is a software library that implements a s...

我在测试仓库中创建以下文件:

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;
}

开始构建:

然后,我通过运行在build文件夹下面生成构建文件,并注意它能够找到SQLite3

> cmake .. -DCMAKE_TOOLCHAIN_FILE=C:/Workspace/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows

-- Building for: Visual Studio 16 2019
-- Using toolchain file: C:/Workspace/vcpkg/scripts/buildsystems/vcpkg.cmake
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.15063.
-- The C compiler identification is MSVC 19.23.28106.4
-- The CXX compiler identification is MSVC 19.23.28106.4
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SQLite3: C:/Workspace/vcpkg/installed/x64-windows/include (found version "3.29.0")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Workspace/testCmake/build

最后,我触发构建,但失败了:

> 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库以与链接时target_link_libraries(),您需要让可执行文件知道在何处可以找到头文件。用途target_include_directories()

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)

如果找到SQLite3(看起来像这样),CMake将填充这些变量:

  • SQLite3_INCLUDE_DIRS:在哪里找到sqlite3.h等
  • SQLite3_LIBRARIES:要使用SQLite3进行链接的库。
  • SQLite3_VERSION:找到SQLite3库的版本
  • SQLite3_FOUNDTRUE如果找到

因此,如果您对的呼叫target_link_libraries()无法正常工作,请尝试使用${SQLite3_LIBRARIES}代替sqlite3

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Windows中编译ZBar示例时出错:无法打开包含文件:'Magick ++。h':没有此类文件或目录

当实现使用CMake实现GLM的库时,“无法打开包含文件”

Visual Studio无法打开包含文件;不能打开包含文件。无此文件或目录

VSTS生成警告:找不到WindowsSDKDir错误:无法打开包含文件:'windows.h'

无法打开包含文件错误,但能够找到文件

PCC-S-02015,“无法打开包含文件”

无法打开包含文件:“ ntddk.h”

如何在Windows Phone上打开包含端口的URL?

Unity:打开包含Windows空间的本地文件

Evince“打开包含文件夹”显示“无法打开包含文件夹”(权限被拒绝)

在安装mysql-python时“无法打开包含文件:'config-win.h':没有这样的文件或目录”

无法为Windows编译PuTTY:致命错误RC1015:无法打开包含文件'winresrc.h'

python打开包含整数的文件

无法在Windows中安装pycocotools:致命错误C1083:无法打开包含文件:io.h:没有此类文件或目录错误:

无法安装 mysqlcient:无法打开包含文件:'mysql.h'

Qt:无法打开包含文件:'QtSql':没有这样的文件或目录

无法打开包含文件:'mysql.h':没有这样的文件或目录

Protobuf:无法在message.pb.h文件中打开包含文件common.h

无法打开包含文件:“ QWebView”:没有此类文件或目录

无法打开包含文件:'cpprest / ws_client':没有此类文件或目录

无法打开包含文件“ src \ gtest-internal-inl.h:”无此文件或目录

无法使用 Qt 打开包含文件:“没有这样的文件或目录”

选择“打开包含文件夹”时,Firefox中出现奇怪的文件关联

_mysql无法打开包含文件:“ config-win.h”:安装mysql-python时没有此类文件或目录

使用cython时发生错误“严重错误C1083;无法打开包含文件:'io.h':没有此类文件或目录”

Windows 应用程序:致命错误 C1083:无法打开包含文件:“gdiplus.h”:没有此类文件或目录

TFS 2018 构建失败:无法打开包含文件“afxres.h”

QtCreator中的“致命错误C1083:无法打开包含文件”

JNI-“无法打开包含文件:'jni_md.h'”