【发布时间】:2021-10-01 08:52:57
【问题描述】:
我用 C++ 和 restbed 框架编写了一个 API。我已经在我的 debian 机器上使用 vcpkg 安装了 restbed。当我发出命令 vcpkg list 时,会显示 restbed 。但是,当我将它包含在我的头文件中并尝试编译时,构建失败并显示
致命错误:找不到“restbed”文件 [build] #include restbed
由于我正在使用 VSCode,在包含 restbed 的头文件中,如果我右键单击它以查看 转到定义,这是一个包含更多文件的 restbedC++ 文件,例如这打开了:
#include "corvusoft/restbed/uri.hpp"
#include "corvusoft/restbed/http.hpp"
#include "corvusoft/restbed/rule.hpp"
#include "corvusoft/restbed/byte.hpp"
这给我的印象是安装了休息床,但我一定错过了一些东西。
我不熟悉 C++,尤其是 WebDev。任何帮助、建议和澄清将不胜感激。谢谢。
CMakeLists.txt 看起来像:
cmake_minimum_required(VERSION 3.18)
project(API)
add_executable(API
main.cpp
CalcResourceFactory.cpp
CalcService.cpp
CalcServiceSettingsFactory.cpp)
file(GLOB SOURCES "*.cpp")
target_link_libraries(API /home/kali/Applications/vcpkg/installed/x64-linux/include/restbed)
target_include_directories(API PUBLIC ${CMAKE_SOURCE_DIR}/include)
set_property(TARGET API PROPERTY CXX_STANDARD 17)
set(CMAKE_TOOLCHAIN_FILE=/home/kali/Applications/vcpkg/scripts/buildsystems/vcpkg.cmake)
虽然我的属性 json 文件看起来像:
{
"configurations": [
{
"name": "Linux",
"includePath":[
"${workspaceFolder}/projectC++Server**",
"/home/kali/Applications/vcpkg/installed/x64-linux/include",
"projectC++Server/include",
"projectC++Server"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
【问题讨论】:
-
@AlanBirtles。我已经添加了上面的文件。
-
我没有使用过 vcpkg 但我认为你没有正确设置你的 cmake 文件 vcpkg.readthedocs.io/en/latest/examples/…,如果在 cmakefile 中设置
CMAKE_TOOLCHAIN_FILE会起作用,我会感到惊讶