gpt4 book ai didi

c++ - 如何在 Mac 上的 VS Code 中处理 C++ 头文件 #include 错误?

转载 作者:行者123 更新时间:2023-12-03 07:03:46 25 4
gpt4 key购买 nike

我的 Mac 上的 VS Code 为 头文件 第三方库 (在本例中为 wxWidgets)产生 #include 错误 。我阅读了我能找到的所有内容,调整了“c_cpp_properties.json”中的“includePath”设置,但没有任何帮助。

头文件与 .cpp 文件位于同一文件夹中(“/src/”)。该项目构建和运行良好,但 VS Code 产生 #include 错误,错误曲线覆盖了我的整个项目。

下面是屏幕截图和带有 VS Code 设置的 JSON 文件。

#include error screenshot

c_cpp_properties.json:

{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/src",
"${workspaceFolder}/**",
"/usr/local/Cellar/wxmac/3.0.5.1/include/wx-3.0"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4

}

请帮我解决这个问题。

———— 更新 ————

建议我在 c_cpp_properties.json 中使用以下设置:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${vcpkgRoot}/x64-osx/include",
"/usr/local/Cellar/wxmac/3.0.5/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4

}

头文件 #include 错误消失了,但第三方库(“WX”)错误仍然存​​在。在上面的JSON中,“includePath”中有一行“${vcpkgRoot}/x64-osx/include”。

这是 vcpkg 包,可帮助轻松安装第三方库。

安装 vcpkg 后,我通过 vcpkg 安装了 wxWidgets,但该库未在 VS Code 中链接(尽管构建得很好),并且出现错误曲线,如下面的屏幕截图所示:

see squiggles – the library is an alien object for VS Code :(

你能解释一下如何理顺吗?

最佳答案

includePath 属性上,将 ** 添加到目录路径的末尾:

...
"includePath": [
"${workspaceFolder}/src/**",
"${workspaceFolder}/**",
"/usr/local/Cellar/wxmac/3.0.5.1/include/wx-3.0/**"
],

您可以在 documentation 上查看有关 c_cpp_properties.json 的更多详细信息

关于c++ - 如何在 Mac 上的 VS Code 中处理 C++ 头文件 #include 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62134590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com