[英]How to deal with C++ header file #include errors in VS Code on Mac?
我的 Mac 上的 VS Code 为header 文件和第三方库(在本例中为wxWidgets )产生#include 错误。 我阅读了我能找到的所有内容,调整了“c_cpp_properties.json”中的“includePath”设置,但没有任何帮助。
Header 文件位于与.cpp 文件相同的文件夹中(“/src/”)。 该项目构建和运行良好,但 VS Code 产生 #include 错误,并且错误曲线覆盖了我的整个项目。
下面是屏幕截图和带有 VS Code 设置的 JSON 文件。
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
}
Header 文件#include 错误消失了,但第三方库(“WX”)错误仍然存在。 在上面的JSON中,“includePath”中写着“${vcpkgRoot}/x64-osx/include”这行。
这是帮助轻松安装第三方库的vcpkg package。
安装vcpkg后,我通过vcpkg安装了wxWidgets ,但是库没有在 VS Code 中链接(虽然构建得很好),并且出现错误曲线,如下面的屏幕截图所示:
你能解释一下如何理顺吗?
在includePath
属性上,将**
添加到目录路径的末尾:
...
"includePath": [
"${workspaceFolder}/src/**",
"${workspaceFolder}/**",
"/usr/local/Cellar/wxmac/3.0.5.1/include/wx-3.0/**"
],
您可以在文档中查看有关c_cpp_properties.json
的更多详细信息
问题的根源在于 WxWidgets 库的defs.h文件中的几个环境变量。 为了让 VS Code 在我的系统(OS X 10.14 Mojave)上识别它们,我必须通过以下方式在c_cpp_properties.json文件中添加“定义” :
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/src/**",
"/usr/local/include/wx-3.1/**",
"/usr/local/lib/wx/include/osx_cocoa-unicode-3.1",
"/usr/local/lib/wx/**"
],
"defines": [
"WX_PRECOMP",
"__WXOSX_COCOA__",
"_FILE_OFFSET_BITS=64",
"__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=1"
],
"forcedInclude": [],
"macFrameworkPath": [],
"compilerPath": "/usr/local/bin/gcc-9",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
此解决方案仅对 Mac 有效。 如果您在包含时遇到相同的错误,或者您是否应该在不同的操作系统上有 class 名称曲线,请在此 GitHub 存储库中查找c_cpp_properties.json文件的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.