# c_cpp_vscode_template **Repository Path**: sp2k_grp/c_cpp_vscode_template ## Basic Information - **Project Name**: c_cpp_vscode_template - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-04-28 - **Last Updated**: 2021-08-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## C/CPP工程模板 launch.json 中需要根据实际情况设置miDebuggerPath的路径 ```C { "version": "0.2.0", "configurations": [ { "name": "Debug", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/bin/main.exe", "miDebuggerPath": "C:/Program Files (x86)/CodeBlocks/MinGW/bin/gdb32.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "preLaunchTask": "build", "linux": { "MIMode": "gdb" }, "osx": { "MIMode": "lldb" }, "windows": { "MIMode": "gdb" } } ] } ``` 默认是使用c。若要使用编译C++工程,则需要把main.c改为main.cpp。 Makefile能源文件的后缀名.c或者.cpp自动选择gcc或者g++命令。 ```C #################################################### # Generic makefile - 万能Makefile # for compiling and linking C++ projects on Linux # Author: George Foot Modified:Jackie Lee #################################################### ### Customising # # Adjust the following if necessary; EXECUTABLE is the target # executable's filename, and LIBS is a list of libraries to link in # (e.g. alleg, stdcx, iostr, etc). You can override these on make's # command line of course, if you prefer to do it that way. # # EXECUTABLE := ./bin/main.exe # 可执行文件名 LIBDIR:= # 静态库目录 LIBS := # 静态库文件名 SRCDIR:= ./src # 除了当前目录外,其他的源代码文件目录 INCLUDES:= $(SRCDIR) ./include # 头文件目录 OBJ_PATH := obj # # # Now alter any implicit rules' variables if you like, e.g.: CC:=gcc CFLAGS := -g -Wall -O0 # -lpthread win下编译线程不加-lpthread也没报错 #CFLAGS := -lpthread -g -Wall -O3 CPPFLAGS := $(CFLAGS) CPPFLAGS += $(addprefix -I,$(INCLUDES)) CPPFLAGS += -MMD # # # The next bit checks to see whether rm is in your djgpp bin # # directory; if not it uses del instead, but this can cause (harmless) # # `File not found' error messages. If you are not using DOS at all, # # set the variable to something which will unquestioningly remove # # files. # RM-F := rm -f # # You shouldn't need to change anything below this point. # PRO.cbp 后缀名第一个字母c,所以将.c*中*去掉 SRCS := $(wildcard *.c) $(wildcard $(addsuffix /*.c, $(SRCDIR))) # 指定*.c文件 CPPSRCS := $(wildcard *.c) $(wildcard $(addsuffix /*.cpp, $(SRCDIR))) # 指定*.cpp文件 SRCS += $(CPPSRCS) OBJS := $(addsuffix .o,$(basename $(SRCS))) DEPS := $(patsubst %.o,%.d,$(OBJS)) MISSING_DEPS := $(filter-out $(wildcard $(DEPS)),$(DEPS)) MISSING_DEPS_SOURCES := $(wildcard $(patsubst %.d,%.c,$(MISSING_DEPS))) .PHONY : all deps objs clean veryclean rebuild info all: $(EXECUTABLE) deps : $(DEPS) objs : $(OBJS) clean : @$(RM-F) *.o @$(RM-F) *.d @$(RM-F) $(OBJS) @$(RM-F) $(DEPS) # 打印 @echo $(RM-F) *.o @echo $(RM-F) *.d @echo $(RM-F) $(OBJS) @echo $(RM-F) $(DEPS) distclean: clean @$(RM-F) $(EXECUTABLE) @echo $(RM-F) $(EXECUTABLE) rebuild: veryclean all ifneq ($(MISSING_DEPS),) $(MISSING_DEPS) : @$(RM-F) $(patsubst %.d,%.o,$@) endif -include $(DEPS) $(EXECUTABLE) : $(OBJS) $(CC) -o $(EXECUTABLE) $(OBJS) $(addprefix -L,$(LIBDIR)) $(addprefix -l,$(LIBS)) info: @echo SRCS: $(SRCS) @echo OBJS: $(OBJS) @echo DEPS: $(DEPS) @echo MISSING_DEPS: $(MISSING_DEPS) @echo MISSING_DEPS_SOURCES: $(MISSING_DEPS_SOURCES) ```