我想一次编译两个.cpp文件。 gstapp.cpp正在编译,gnew.cpp被忽略。我忽略了什么?
生成文件:
# generated from pkg-config --cflags gstreamer-0.10
CFLAGS=-pthread -I/usr/include/gstreamer-0.10 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libxml2
# generated from pkg-config --libs gstreamer-0.10
LDFLAGS=-lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -pthread -lgthread-2.0 -pthread -lglib-2.0 -lxml2 -lgstapp-0.10
CFLAGS+=-I/usr/include/opencv2
# there are more, but not needed form now: -lopencv_calib3d -lopencv_contrib -lopencv_flann -lopencv_obj
LDFLAGS+=-lstdc++ -lopencv_core -lopencv_features2d -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_video
gstapp: gstapp.o
gcc $(LDFLAGS) -o $@ $<
gstapp.o: gstapp.cpp
gcc -c $(CFLAGS) -o $@ $<
gnew: gnew.o
gcc $(LDFLAGS) -o $@ $<
gnew.o: gnew.cpp
gcc -c $(CFLAGS) -o $@ $<
最佳答案
您可能希望使用all
规则来触发两者的编译。通过只运行不带参数的make
,它将运行它遇到的第一个规则(例如gstapp:
),然后退出。
因此,在LDFLAGS和gstapp行之间放
all: gstapp gnew
然后,这第一个(也就是默认)规则将两个文件都作为依赖项,并在运行
make
或make all
时都进行编译。