通过 Makefile 编译 2 个文件不起作用
Compile 2 files via Makefile doesn't work
我想一次编译两个.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
规则来触发两者的编译。通过 运行ning make
不带参数,它将 运行 它遇到的第一个规则(例如 gstapp:
)然后退出。
所以在 LDFLAGS 和 gstapp 行之间放
all: gstapp gnew
第一个(又名默认)规则将把你的两个文件作为依赖项,并在你 运行 make
或 make all
.
时编译它们
我想一次编译两个.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
规则来触发两者的编译。通过 运行ning make
不带参数,它将 运行 它遇到的第一个规则(例如 gstapp:
)然后退出。
所以在 LDFLAGS 和 gstapp 行之间放
all: gstapp gnew
第一个(又名默认)规则将把你的两个文件作为依赖项,并在你 运行 make
或 make all
.