[英]Creating a makefile for g++ compiler
I have some code that everytime I want to compile I have to do the following command in the linux shell (just an example): 我有一些代码,每次我想编译时,都必须在linux shell中执行以下命令(仅作为示例):
$g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux64 -o sim helloworld.cpp -lsystemc -lm
In this example my source file is helloworld.cpp
and I want it to be compiled in a folder called sim
in the same folder where the source file is. 在此示例中,我的源文件是helloworld.cpp
,我希望将其编译在与源文件相同的文件夹中的sim
文件夹中。
How can I automate this process using make
or makefile
. 如何使用make
或makefile
自动执行此过程。 Also having the make clean
option to remove the created folder if called? 还具有make clean
选项来删除创建的文件夹(如果调用)吗?
If you rename your cpp file to sim.cpp
this is probably the simplest Makefile 如果将cpp文件重命名为sim.cpp
这可能是最简单的Makefile
CPPFLAGS := -I. -I$(SYSTEMC_HOME)/include
LDFLAGS := -L. -L$(SYSTEMC_HOME)/lib-linux64
LDLIBS := -lsystemc -lm
sim:
.PHONY: clean
clean: ; $(RM) sim
The implicit rules should handle everything else for you 隐式规则应该为您处理其他一切
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.