如何将目标文件放入目录中

时间:2013-09-11 10:26:04

标签: makefile

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

Makefile

# 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) 

1 个答案:

答案 0 :(得分:1)

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

尝试:

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

...

obj/%.o : %.cpp
        $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<