当前位置:   article > 正文

MacOS 配置VSCode C/C++ 开发和环境_c++ macos

c++ macos

1、下载VSCode

        https://code.visualstudio.com/Download

2、安装C/C++插件:

按快捷键:shift+command+X

并在搜索框输入 c/c++,然后点击进行安装

  1. C/C++,这个肯定是必须的:
  2. 2)、 C/C++ Snippets,即 C/C++重用代码块。
  3. 3)、 C/C++ Advanced Lint,即 C/C++静态检测 。
  4. 4)、 Code Runner,即代码运行。
  5. 5)、 Include AutoComplete,即自动头文件包含。
  6. 6)、 Rainbow Brackets,彩虹花括号,有助于阅读代码。
  7. 7)、 One Dark Pro, VSCode 的主题。
  8. 8)、 GBKtoUTF8,将 GBK 转换为 UTF8
  9. 9)、 ARM,即支持 ARM 汇编语法高亮显示。
  10. 10)、 Chinese(Simplified),即中文环境。
  11. 11)、 vscode-icons, VSCode 图标插件,主要是资源管理器下各个文件夹的图标。
  12. 12)、 compareit,比较插件,可以用于比较两个文件的差异。
  13. 13)、 DeviceTree,设备树语法插件。
  14. 14)、 TabNine,一款 AI 自动补全插件,强烈推荐,谁用谁知道!

3、打开项目文件:

 新建 hello.c 文件,

  1. #include <stdio.h>
  2. int main(){
  3. printf("hello world");
  4. return 0;
  5. }

4. 配置json文件

这里需要配置3个JSON文件 c_cpp_properties.json、tasks.json、launch.json

4.1、配置 c_cpp_properties.json

  • 使用快捷键command+shift+p打开命令行面板(Command Palette)
  • 输入edit configurations,在弹出的列表中选择带JSON的C/C++:Edit Configurations(JSON)

        此时会自动新增.vscode文件夹,并新建c_cpp_properties.json文件:

  1. {
  2. "configurations": [
  3. {
  4. "name": "Mac",
  5. "includePath": [
  6. "${workspaceFolder}/**",
  7. "/Library/Developer/CommandLineTools/usr/include/c++/v1",
  8. "/usr/local/include",
  9. "/Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include",
  10. "/Library/Developer/CommandLineTools/usr/include"
  11. ],
  12. "defines": [],
  13. "macFrameworkPath": [],
  14. "compilerPath": "/usr/local/bin/gcc-9",
  15. "cStandard": "gnu17",
  16. "cppStandard": "gnu++14",
  17. "intelliSenseMode": "macos-gcc-x64"
  18. }
  19. ],
  20. "version": 4
  21. }

这里你需要看看你的 clang是多少版本,我的是9.1.0,注意要修改为你自己的                        cd /Library/Developer/CommandLineTools/usr/lib/clang 进入文件夹 查看clang版本

4.1、配置 tasks.json

  • 敲击快捷键 command+shift+P,输入tasks:configure task,选择Tasks:Configure Task
  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": "c++",
  8. "command": "clang++",
  9. "type": "shell",
  10. "args": [
  11. "./c++/hello.cpp",
  12. "-std=c++11",
  13. "-g"
  14. ],
  15. "presentation": {
  16. "echo": true,
  17. "reveal": "always",
  18. "focus": false,
  19. "panel": "shared"
  20. }
  21. }
  22. ]
  23. }

4.1、配置 launch.json

  • 打开命令行面板 command+shift+P, 输入launch, 选择Open launch.json
  1. {
  2. // 使用 IntelliSense 了解相关属性。
  3. // 悬停以查看现有属性的描述。
  4. // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  5. "version": "0.2.0",
  6. "configurations": [
  7. {
  8. "name": "c/c++ Launch",
  9. "type": "cppdbg",
  10. "request": "launch",
  11. "program": "${workspaceFolder}/a.out",
  12. "args": [],
  13. "stopAtEntry": false,
  14. "cwd": "${workspaceFolder}",
  15. "environment": [],
  16. "externalConsole": true,
  17. "MIMode": "lldb",
  18. "preLaunchTask":"c++"
  19. }
  20. ]
  21. }

若是生成不了这三个json文件,你就新建文件命名为这三个json文件,把内容复制进去

这个地方只需配置一次就可以了,如果想开启新的工程,直接新建文件就可以了

5. 运行

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/315584?site=
推荐阅读
相关标签
  

闽ICP备14008679号