欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

VSCode C++编译调试 Mac,vscodemac

来源: javaer 分享于  点击 20344 次 点评:93

VSCode C++编译调试 Mac,vscodemac


1.mac下用c++-clang智能提示,mac下我这是安装过clang的,应该是mac自带的吧,在shell中输入whereis clang看下路径。在vscode中按home+shift+p 输入open user settings 配置clang:

{ "clang.executable": "/usr/bin/clang", }

重启后就有智能提示了,和resharper比,反应很慢,差距很大,不过还是很舒服了


2.安装插件:C/C++,配置核心文件:launch.json tasks.json

launch.json:一个debug 一个release 这里面的参数 可以百度 有详细说明,我这主要就说下关键的 name、program 、 prelaunchtask、cwd,name就是调试使用配置文件的名称,program要调试的文件完整路径,cwd调试目录,prelaunchtask 调试前要执行的task名称

{ "version": "0.2.0", "configurations": [ { "name": "debug", "type": "cppdbg", "request": "launch", "program": "${workspaceRoot}/main", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "MIMode": "lldb", "preLaunchTask": "debug" }, { "name": "release", "type": "cppdbg", "request": "launch", "program": "${workspaceRoot}/main", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "MIMode": "lldb", "preLaunchTask": "release" } ] }

tasks.json

{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "taskName": "debug", "type": "shell", "command": "make" }, { "taskName": "release", "type": "shell", "command": "make release" } ] }

我这还是很标准的考虑多文件编译、跨平台、兼容性用了makefile ,那么task中command执行make即可,这样感觉清晰和方便了不少


3.makefile

CC=g++ TARGET=main SRC=$(shell echo *.cpp) OBJ=$(SRC:$.cpp=$.o) CFLAGS= -std=c++11 .PHONY:clean
debug:     $(CC) -g -c$(SRC)$(CFLAGS)     $(CC) -o$(TARGET)$(OBJ) release:     $(CC) -c$(SRC)$(CFLAGS)     $(CC) -o$(TARGET)$(OBJ)     make clean clean:     rm -fr *.o




相关文章

    暂无相关文章

用户点评