蘭雅sRGB 个人笔记 https://262235.xyz
提供编程和电脑应用视频教程,工具和源代码
C, C++, Python Programming, Source Code, Video

旧Hexo博客 | Github | IP定位WebAPI | Docker Hub
编程中文文档 | 网盘分享 | 中文Linux命令

VS Code和TDM Gcc 使用 Makefile 编译学习 Windows 程序设计

vscode_gcc.png

使用 C/C++ Makefile Project 插件建立 Makefile

  • ctrl+shift+p, 插件选择 Only C++ Makefile

修改过的 Makefile 添加了 windres.exe 编译 resource.rc

Makefile.png

Makefile

# Compiler settings - Can be customized.
CC = g++
WINDRES = windres.exe
CXXFLAGS = -Wall -O2 -std=c++11 -fexec-charset=gbk -finput-charset=UTF-8
LDFLAGS =  -s -shared-libstdc++  -lgdi32 -luser32 -lkernel32 -lcomctl32 -mwindows

# Makefile settings - Can be customized.
APPNAME = WinKcp_Launcher
EXT = .cpp

SRCDIR = .
OBJDIR = .

############## Do not change anything from here downwards! #############
SRC = $(wildcard $(SRCDIR)/*$(EXT))
OBJ = $(SRC:$(SRCDIR)/%$(EXT)=$(OBJDIR)/%.o)
DEP = $(OBJ:$(OBJDIR)/%.o=%.d)

####################### Targets beginning here #########################
all: $(APPNAME)

# Builds the app
$(APPNAME): $(OBJ)
    $(WINDRES)  -J rc -O coff -i resource.rc -o resource.res 
    $(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)  resource.res

# Includes all .h files
-include $(DEP)

# Building rule for .o files and its .c/.cpp in combination with all .h
$(OBJDIR)/%.o: $(SRCDIR)/%$(EXT) 
    $(CC)  $(CXXFLAGS) -o $@ -c $<
本原创文章自由转载,转载请注明本博来源及网址 | 当前页面:兰雅sRGB个人笔记 » VS Code和TDM Gcc 使用 Makefile 编译学习 Windows 程序设计