2011-03-11 72 views
1

我試圖編譯使用2個.cc的文件和.H簡單的makefile問題

我正在寫一個Makefile,但它不是編譯一個項目,我得到一個錯誤:

make 
g++ -I/usr/local/include/ -I/usr/local/include/libfreenect -I. -I/usr/include/GL -fPIC -g -Wall `pkg-config --cflags opencv` -L/usr/X11R6/lib -L/usr/lib -L/lib simple_gesture.cc -o simple_gesture `pkg-config --libs opencv` -L/usr/local/lib -lfreenect -lglui -lglut -lGLU -lGL 
simple_gesture.cc: In function ‘void depth_cb(freenect_device*, void*, uint32_t)’: 
simple_gesture.cc:315: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘clock_t’ 
simple_gesture.cc:315: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ 
/tmp/cck2APvc.o: In function `depth_cb(_freenect_device*, void*, unsigned int)': 
/home/dany/ToCompile/kinect-apps-playground-fingertip-detection/simple_gesture.cc:313: undefined reference to `FeatureExtractor::Process(unsigned char*, int const*, int)' 
collect2: ld returned 1 exit status 
make: *** [simple_gesture] Error 1 

Makefile的是這樣的:

all: simple_gesture 

CFLAGS=-fPIC -g -Wall `pkg-config --cflags opencv` 
LIBS = `pkg-config --libs opencv` 
INCLUDE = -I/usr/local/include/ -I/usr/local/include/libfreenect -I. -I/usr/include/GL 
FREE_LIBS = -L/usr/local/lib -lfreenect 
GL_LIBS = -lglui -lglut -lGLU -lGL 
GL_FLAGS = -L/usr/X11R6/lib -L/usr/lib -L/lib 

feature_extractor: feature_extractor.h feature_extractor.cc 
    $(CXX) $(INCLUDE) $(CFLAGS) $(GL_FLAGS) $? -o [email protected] $(LIBS) $(FREE_LIBS) $(GL_LIBS) 

simple_gesture: simple_gesture.cc 
    $(CXX) $(INCLUDE) $(CFLAGS) $(GL_FLAGS) $? -o [email protected] $(LIBS) $(FREE_LIBS) $(GL_LIBS) 

%.o: %.c 
    $(CXX) -c $(CFLAGS) $< -o [email protected] 

clean: 
    rm -rf *.o feature_extractor simple_gesture 

我覺得我沒有縫好了的文件..

任何想法?

[編輯] 解決

這已經足夠了:

simple_gesture:feature_extractor.h feature_extractor.cc simple_gesture.cc $(CXX)$(含)$(CFLAGS)$(GL_FLAGS)$ ? -o $ @ $(LIBS)$(FREE_LIBS)$(GL_LIBS)

+0

什麼是過程()函數feature_extractor?錯誤是鏈接錯誤,所以你可能需要包含另一個文件。 – MByD 2011-03-11 13:01:10

+0

是進程是feature_extractor。我不認爲我需要另一個包含,我認爲問題只是Makefile,因爲這個代碼也被其他人使用 – azinos 2011-03-11 14:07:56

回答

1

顯然你simple_gesture.cc取決於一些功能從FeatureExtractor類。因此,您應該考慮將feature_extractor.o併入您的simple_gesture

+0

是的我正在考慮類似的事情,但我不知道如何在Makefiles中這樣做,因爲如果我這樣做:all:simple_gesture feature_extractor我得到其他錯誤 – azinos 2011-03-11 14:05:33

+0

@azinos:請參閱@ florin的回答:) – 2011-03-11 18:03:42

0

您需要使二進制文件取決於目標文件的存在,而不是源文件。您已經有了將源代碼轉換爲對象的規則。

all: simple_gesture 

LIBS = `pkg-config --libs opencv` 
INCLUDE = -I/usr/local/include/ -I/usr/local/include/libfreenect -I. -I/usr/include/GL 
FREE_LIBS = -L/usr/local/lib -lfreenect 
GL_LIBS = -lglui -lglut -lGLU -lGL 
GL_FLAGS = -L/usr/X11R6/lib -L/usr/lib -L/lib 
CFLAGS=-fPIC -g -Wall `pkg-config --cflags opencv` $(INCLUDE) 

feature_extractor: feature_extractor.o 
    $(CXX) $(GL_FLAGS) -o [email protected] $(LIBS) $(FREE_LIBS) $(GL_LIBS) $< 

simple_gesture: simple_gesture.o feature_extractor.o 
    $(CXX) $(GL_FLAGS) -o [email protected] $(LIBS) $(FREE_LIBS) $(GL_LIBS) $< 

%.o: %.cc 
    $(CXX) -c $(CFLAGS) -o [email protected] $< 

clean: 
    rm -rf *.o feature_extractor simple_gesture