首页 > 编程语言 > 详细

MacOS配置vscode C++编译环境

时间:2021-04-05 12:31:20      阅读:25      评论:0      收藏:0      [点我收藏+]

参考资料: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++即可。

 

MacOS配置vscode C++编译环境

原文:https://www.cnblogs.com/dormin/p/14617817.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!