launch.json
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) 启动", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/pro", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true }, ], "preLaunchTask": "build", "miDebuggerPath": "/usr/bin/gdb" } ] }
tasks.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "make pro", "options": { "cwd": "${workspaceFolder}" } } ] }
makefile
src_directory := src obj_directory := obj srcs := $(shell find $(src_directory) -name "*.cpp") objs := $(patsubst %.cpp,%.o,$(srcs)) objs := $(subst $(src_directory),$(obj_directory),$(objs)) .PHONY: debug run debug: @echo $(objs) pro: ${objs} @g++ $^ -o $@ run:pro @./pro $(obj_directory)/%.o : $(src_directory)/%.cpp @g++ -g -c $< -o $@ # $< 第一个生产项 # $^ 所有的生成项 # $@ 第一个生产项
src_directory := src obj_directory := obj srcs := $(shell find $(src_directory) -name "*.cpp") objs := $(patsubst %.cpp,%.o,$(srcs)) objs := $(subst $(src_directory),$(obj_directory),$(objs)) .PHONY: debug run clean: @rm -rf objs pro debug: @echo $(objs) pro: ${objs} @g++ $^ -o $@ run:pro @./pro #生成项$@ #$< 依赖项 # @mkdir -p $(dir #@) 可以生成多级目录 $(obj_directory)/%.o : $(src_directory)/%.cpp @mkdir -p $(dir #@) @g++ -g -c $< -o $@ # $< 第一个生产项 # $^ 所有的生成项 # $@ 第一个生产项
cc := @g++ source_dir := src object_dir := objs output_brinay_name := pro sources := $(shell find src -name "*.cpp") objects := $(patsubst %.cpp,%.o,$(sources)) objects := $(subst $(source_dir)/,$(object_dir)/,$(objects)) # compile_flags := std=c++ -O0 -g compile_flags := link_flags := .PYTHOY : debug clean run $(object_dir)/%.o : $(source_dir)/%.cpp @mkdir -p $(dir $@) @echo Compile $< $(cc) -c $< -o $@ $(compile_flags) $(output_brinay_name) : $(objects) @echo Link $@ $(cc) -o $@ $^ $(link_flags) run :$(output_brinay_name) ./$(output_brinay_name) clean : @rm -rf $(object_dir) $(output_brinay_name) debug: @echo $(objects)