0

嗨,使用下面的 make 文件,我如何将所有目标文件创建到目录 obj 中。可能这个问题很简单但不知道该怎么做?

生成文件

# Makefile

 #### variables
 RM= rm -vf

 CXX         =   g++

 CXXFLAGS    =  -Wall -g

 CPPFLAGS    =  -I/usr/include/opencv -I/usr/include/opencv2 

 LDLIBS      =  -pthread -lbluetooth -lopencv_core -lopencv_imgproc -lopencv_highgui \
            -lopencv_ml -lopencv_video -lopencv_features2d \
            -lopencv_calib3d -lopencv_objdetect -lopencv_contrib \
            -lopencv_legacy -lv4l1 -lv4l2 -lv4lconvert 

 SOURCEFILES =  main.cpp     \
        bluetooth.cpp \
        gpio.cpp \
        wifi.cpp \
        capturAndSend.cpp  \


 OBJECTFILES = $(patsubst %.cpp,%.o,$(SOURCEFILES))

 PROGNAME= server

 ### rules
 .PHONY: all clean

 all: $(PROGNAME)
 $(PROGNAME): $(OBJECTFILES)
    $(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@

 clean:
    $(RM) $(OBJECTFILES) $(PROGNAME) 
4

1 回答 1

1

这个问题已经有很多很多的答案了。你看了吗?

尝试:

OBJECTFILES = $(patsubst %.cpp,obj/%.o,$(SOURCEFILES))

...

obj/%.o : %.cpp
        $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
于 2013-09-11T13:17:00.203 回答