VScode的下载地址:
https://code.visualstudio.com/Download
网站中包含了通用安装包(稍大)、Intel芯片专属安装包以及苹果芯片安装包,为了方便这里直接选择Universal进行下载。
点击后文件开始下载。
若此时下载速度很慢甚至几分钟后下载终端,可以切换为国内的下载镜像,具体方法为:
复制链接到新的页面,将网址中stable之前的地址改为国内镜像地址:vscode.cdn.azure.cn
下载速度会变得飞快。
下载完成后,解压压缩包,并将文件拖入应用程序即可。
clang++ --version
如已经安装会显示如下的版本号,如未安装,按照提示先安装编译器clang++, xcode在这里不是必须要安装的,只不过安装了xcode,相应的编译器也顺带安装了,如果不进行ios等相关的开发,仅安装clang++也是可以。
2. 打开安装好的VScode,安装如下的插件:
安装插件C\C++ (编辑、调试C/C++程序),C\C++ Clang Command Adapter,CodeLLDB(Mac下一定要安装这个插件,用来debug,解决Catalina不支持lldb调试问题)以及code runner(用来编译)。
3. 新建文件夹,并使其成为vscode的工作目录。
3.1 文件夹新建
3.2 file -> open folder -> 选择新建的文件夹
4. 新建cpp文件, 如firstcase.cpp, 编写简单的hello, world程序。
#include
using namespace std;
int main()
{
for(int i=0;i<5;i++)
{
cout<<"hello, vscode"<<endl;
}
return 0;
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "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": {
"kind": "build",
"isDefault": true
}
}
]
}
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": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${fileDirname}/${fileBasenameNoExtension}",
//"terminal": "external",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
另外需要注意的一点:如果更改了程序的内容,保存之后,需要重新shift+command+B,产生新的.out文件,这样再按F5调试才是修改后的结果,否则仍然是修改前的结果。
[1]: https://blog.csdn.net/Vinsuan1993/article/details/103983520
[2]: https://blog.csdn.net/neptune4751/article/details/105925558/
[3]: https://blog.csdn.net/fujz123/article/details/104426121
[4]: https://code.visualstudio.com/docs/cpp/config-clang-mac
[5]: https://blog.csdn.net/xucee/article/details/115034505