Linux的最低C ++ Make文件 [英] minimum c++ make file for linux
问题描述
我一直在寻找适合Linux的简单推荐的最小" c ++ makefile,它将使用g ++编译并链接单个文件和h文件.理想情况下,make文件中甚至不包含物理文件名,而仅包含从.cpp到.o的转换.生成此类makefile而不用担心autoconf的恐怖的最佳方法是什么?
I've looking to find a simple recommended "minimal" c++ makefile for linux which will use g++ to compile and link a single file and h file. Ideally the make file will not even have the physical file names in it and only have a .cpp to .o transform. What is the best way to generate such a makefile without diving into the horrors of autoconf?
例如,当前目录包含
t.cpp t.h
t.cpp t.h
,我希望为此创建一个makefile.我尝试了autoconf,但假设.h是gcc而不是g ++.是的,虽然不是初学者,但我从几年前开始学习最佳的项目处理方法,因此我正在寻找为小型项目创建和维护makefile的自动化方法.
and I want a makefile for that to be created. I tried autoconf but its assuming .h is gcc instead of g++. Yes, while not a beginner, I am relearning from years ago best approaches to project manipulation and hence am looking for automated ways to create and maintain makefiles for small projects.
推荐答案
如果是单个文件,则可以键入
If it is a single file, you can type
make t
它将调用
g++ t.cpp -o t
这甚至不需要目录中的Makefile,尽管如果您有t.cpp,t.c和t.java等,它将使您感到困惑.
This doesn't even require a Makefile in the directory, although it will get confused if you have a t.cpp and a t.c and a t.java, etc etc.
也是一个真实的Makefile:
Also a real Makefile:
SOURCES := t.cpp
# Objs are all the sources, with .cpp replaced by .o
OBJS := $(SOURCES:.cpp=.o)
all: t
# Compile the binary 't' by calling the compiler with cflags, lflags, and any libs (if defined) and the list of objects.
t: $(OBJS)
$(CC) $(CFLAGS) -o t $(OBJS) $(LFLAGS) $(LIBS)
# Get a .o from a .cpp by calling compiler with cflags and includes (if defined)
.cpp.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $<
这篇关于Linux的最低C ++ Make文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!