[英]Compile/Link a C++ project using python
So i have a somewhat large C++ project that I want to compile.Previously I used Code::Blocks, but now I want more control about what's happening behind the scenes.所以我有一个有点大的 C++ 项目,我想编译。以前我使用 Code::Blocks,但现在我想要更多地控制幕后发生的事情。 However making makefiles was just too complex for me!!然而,制作makefile对我来说太复杂了!!
What I want is this: Can i create a python script that acts as a makefile, if so how?!我想要的是:我可以创建一个充当 makefile 的 python 脚本吗,如果可以,怎么做?!
In the makefile I want to search for all *.cpp files on certain directories and then invoke g++ to compile/link them.在生成文件中,我想搜索某些目录上的所有 *.cpp 文件,然后调用 g++ 来编译/链接它们。
EDIT: sorry i forgot to mention i also have headers and want custom g++ parameters编辑:对不起,我忘了提到我也有标题并想要自定义 g++ 参数
Try that:试试看:
#default target
all: prog
#auto dependency
include $(OBJ_FILES:.o=.d)
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $*.cpp -o $*.o
$(CXX) -MM $(CXXFLAGS) $*.cpp > $*.d
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.
#set ld flags eg for libs
LDFLAGS = -lsdl2 -lglew -lgl
#set cxxflags for all debug options and others
CXXFLAGS= -g -Wall
#collect all cpp files:
CPP_FILES := $(shell find . -type f -name '*.cpp')
#get the object file names for them
OBJ_FILES := $(CPP_FILES:.cpp=.o)
#and link all togeter
prog: $(OBJ_FILES)
g++ $(CXXFLAGS) $(LDFLAGS) -o $@ $^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.