说明
最近配置MAC上CPP的运行环境,在安装必要的CPP插件后,配置launch和task等json文件后,点击运行三角形,每次都会跳出main想要访问桌面上的文件。并且输出也是在调试控制台,非常逆天。
尝试
尝试1:尽管我尝试将tasks.json文件上的panel改为new,仍然无济于事。
尝试2:赋予vscode桌面访问权限。
这里感觉很无语的main程序获取访问权限,猜测是mac系统对进程赋予权限的设置有bug。我们每次起一遍main,mac系统都不能识别到已经赋予的访问权限。
解决办法
解决办法:安装code runner插件,不要用vscode自带的运行(真的很难用 )。
其他
.vscode/c_cpp_properties.json
{"configurations": [{"name": "Mac","includePath": ["${workspaceFolder}/**"],"defines": [],"macFrameworkPath": ["/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"],"compilerPath": "/usr/bin/clang++","cStandard": "c17","cppStandard": "c++17","intelliSenseMode": "macos-clang-x64"}],"version": 4
}
.vscode/launch.json
{"version": "0.2.0","configurations": [{"type": "lldb","request": "launch","name": "mydb","program": "${fileDirname}/${fileBasenameNoExtension}","args": [],"cwd": "${workspaceFolder}","preLaunchTask": "Build with Clang"}]}
注意type改成lldb,program选项填生成的可执行文件,cwd选项填当前工作路径,preLaunchTask选项填写tasks.json的label。
.vscode/tasks.json
{"version": "2.0.0","tasks": [{"label": "Build with Clang","type": "shell","command": "clang++","args": ["-std=c++17","-stdlib=libc++","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}","--debug"],"group": "build"},]
}
注意label选项,type应该无所谓,args要填对,-g是要编译的文件,-o是编译输出文件名。