• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Abscisic_Acid
博客园    首页    新随笔    联系   管理    订阅  订阅
MacOS配置vscode C++编译环境

参考资料:https://www.cnblogs.com/2018shawn/p/13580555.html

参考资料:https://blog.csdn.net/deaidai/article/details/82955010

 

1.首先在appstore中下载xcode

2.接下来进入在windows中下载vscode的dmg版本并拷贝到mac盘上(如果能够在mac系统里完成下载那是最好的,但是我一次也没成功过)

3.打开vscode的扩展市场,下载两款插件C/C++和C/C++ Clang Command Adapter

4.接下来打开一个文件夹,作为你的编译环境。

在文件夹内创建.vscode文件夹

下创建launch.json以及tasks.json

lanuch.json

 1 {
 2     // 使用 IntelliSense 了解相关属性。 
 3     // 悬停以查看现有属性的描述。
 4     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
 5     "version": "0.2.0",
 6     "configurations": [
 7         {
 8             "name": "启动C++",
 9             "type": "cppdbg",
10             "request": "launch",
11             "program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
12             "args": [],
13             "stopAtEntry": false,
14             "cwd": "${workspaceFolder}",
15             "environment": [],
16             "externalConsole": true,
17             "MIMode": "lldb",
18             "preLaunchTask": "Run Cpp"
19         }
20     ]
21 }
View Code

tasks.json

 1 {
 2     // See https://go.microsoft.com/fwlink/?LinkId=733558
 3     // for the documentation about the tasks.json format
 4     "version": "2.0.0",
 5     "tasks": [
 6         {
 7             "label": "Run Cpp",
 8             "type": "shell",
 9             "command": "g++",
10             "args": [
11                 "-g",
12                 "${file}",
13                 "-o",
14                 "${fileBasenameNoExtension}.out"
15             ],
16             "group": {
17                 "kind":"build",
18                 "isDefault": true
19             },
20             
21         },
22         {
23             "label": "Open Terminal",
24            "type": "shell",
25            "command": "osascript -e 'tell application \"Terminal\"\ndo script \"echo hello\"\nend tell'",
26            "problemMatcher": []
27         }
28         
29     ]
30 }
View Code

其中有几个关键信息。

launch.json中"preLaunchTask": "Run Cpp"即为运行前先运行task的编译程序,就不用再手动编译了。"Run Cpp"是在tasks.json里设置的label。

launch.json中"externalConsole": true是外显终端,目的在于不在内置终端中运行。

 

5.接下来是激活终端。

首先点开左侧调试运行栏,点击启动,然后会出现终端并且需要输入密码的情况。如果没有,在终端中输入

DevToolsSecurity -enable

 6.然后在vscode的命令面板(用cmd+shift+p呼出)输入Run Task,点击Open Terminal。在打开的终端前点击OK!即可完成全部的激活。

7.新建一个cpp文件,写一段代码,然后按左侧的调试界面,点击启动C++即可。

 

posted on 2021-04-05 09:35  Abscisic_Acid  阅读(741)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3