ruijiege

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

 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"
        }
    ]
}
View Code

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}"
            }
        }
    ]
}
View Code

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 $@


# $< 第一个生产项
# $^ 所有的生成项
# $@ 第一个生产项
View Code

 

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 $@


# $< 第一个生产项
# $^ 所有的生成项
# $@ 第一个生产项
View Code

 

 

 

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)
View Code

 

posted on 2022-10-25 17:07  哦哟这个怎么搞  阅读(82)  评论(0编辑  收藏  举报