MacOS下用VScode搭建一个简单的C++环境

零妖贰捌 问答 2261

所参考的视频链接 (需要梯子)

[1]How to Run C++ in Visual Studio Code on Mac OS 2020
[2]Debugging C/C++ with Visual Studio Code
这些是我在搭建时候参考的视频。

图文流程

How to Run C++ In VScode

  1. 下载homebrew
    国内下载homebrew的方法
  2. 下载MinGW
    打开terminal->输入brew install mingw-w64
  3. 下载VScode
    Vscode下载链接
  4. 在VScode下载扩展
    打开VScode (安装code runner,c++,clang++)

  5. 创建cpp文件并进行编译

Debugging C++ with Vscode

  1. configure Task
    command+shift+P -> configure task -> otherrs -> 修改 task.json
{ "tasks": [ { "type": "shell", "label": "C/C++: 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 }, "detail": "Generated task by Debugger" } ], "version": "2.0.0" }
  1. configure launch
    command+shfit+p -> open launch.json -> C++(GDB/LLDB) -> clang++ -> 修改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": [ { "name": "clang++ - 生成和调试活动文件", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "lldb", "preLaunchTask": "C/C++: clang++ build active file" } ] }

刚开始编译可能出现的问题 (后续可能添加)

没有保存就开始编译

如果没有保存就编译的话,编译时会出现

Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64


开启Vscode中的autosave就可以了(百度有教程)

回复

我来回复
  • 暂无回复内容

公众号
公众号
创建WIFI码
创建WIFI码
在线客服
分享本页
返回顶部