Q1:c_cpp_properties.json文件中的macFrameworkPath参数配置

​官网​​上给定内容如下:

{
"configurations": [
{
"name": "Mac",
"includePath": ["${workspaceFolder}/**"],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}

但是,在运行中系统提示找不到上述路径“/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks”。

经分析发现macFrameworkPath参数的含义是:为了指向系统的头文件,而此文件对应于MAC系统上XCode下的一个路径。

明确了此参数含义后,发现在本人机器上上述路径参数应该修改为:

"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"

问题得到解决。

Q2:NSCocoaErrorDomain相关错误

dsymutil[1705:43670] There was an error parsing the Info.plist for the bundle at URL <0x7fd839d11660>: NSCocoaErrorDomain - 3840

具体显示错误如下图所示:

MAC平台上VSCode搭建C++开发环境遭遇问题_System

在安装Visual Studio Code前我刚刚升级了XCode有关文件(细节没有检查,但是在启动XCode启动时要求自动远程更新的)。

目前为止,搜索了百度与谷歌、必应,都没有找到相应针对性病因。

但是,目前针对VSCode下C++程序的调试与运行还没有发现其他障碍性作用(可正常调试与运行)。

后面有时间会继续分析这个错误病因。

附:我目前MAC上能够完整调试运行与正常运行的配置文件内容

【1】launch.json,此文件主要与调试有关,但是也不尽然:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: clang++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang++ build active file"
}
]
}

重要声明:externalConsole参数的含义是:是否启动外部控制台程序,在我的机器中,必须设置为true ;如果设置为false,即意味着使用VSCode内置的终端,但是由于下列错误的存在,无法正常运行程序:

dsymutil[1601:31403] There was an error parsing the Info.plist for the bundle at URL <0x7fceb5412c20>: NSCocoaErrorDomain - 3840

【2】tasks.json,此文件主要与C++程序的编译运行有关:

{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
]
}

【3】c_cpp_properties.json:which allows you to change settings such as the path to the compiler, include paths, which C++ standard to compile against (such as C++17), and more.

{
"configurations": [
{
"name": "Mac",
"includePath": ["${workspaceFolder}/**"],
"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"
}
],
"version": 4
}

后记1

到目前为止,下列错误仍然存在,但是根据上面描述,程序算是还能够正常运行(是否完全这样,还有待进一步确定):

dsymutil[1601:31403] There was an error parsing the Info.plist for the bundle at URL <0x7fceb5412c20>: NSCocoaErrorDomain - 3840

后记2

今天刚刚在我的MAC上成功安装完基于VirtualBox 6的NOI Linux 2,在虚拟机的内置(看起来NOI官方已经预先调整好了其中的VSCode)。发现在使用其中的VSCode时,完全可以正常使用其内置的Terminal,进行调试也非常正常。

后记3

MAC平台上VSCode搭建C++开发环境遭遇问题_System_02

上图是在我的机器中使用VSCODE中的菜单中的【运行】-【以非调试模式运行】时的内置终端的输出形式。其实,上面对应两个错误,对于最后的提示【终端将被任务重用...】,可以通过参考后面引文调整一下文件tasks.json内容即可修改。

​参考文章​​。调整后的完整内容如下:

{
"version": "2.0.0",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated", //任务间不共享面板, 同一个任务共享相同面板.
"showReuseMessage": false, //控制是否显示“终端将被任务重用, 按任意键关闭”提示.
"clear": false
}, //如果这是你最后一部分内容,就把这个逗号去掉。
"tasks": [
{
"type": "shell",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
]
}