VSCode C++编译调试 Mac

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




  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值