我正在尝试编译一个使用2 .cc文件和.h
的项目我正在写一个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 $@ $(LIBS) $(FREE_LIBS) $(GL_LIBS)
simple_gesture: simple_gesture.cc
$(CXX) $(INCLUDE) $(CFLAGS) $(GL_FLAGS) $? -o $@ $(LIBS) $(FREE_LIBS) $(GL_LIBS)
%.o: %.c
$(CXX) -c $(CFLAGS) $< -o $@
clean:
rm -rf *.o feature_extractor simple_gesture
我认为我没有很好地链接文件..
有什么想法吗?
[编辑] 解决
这就足够了:
simple_gesture:feature_extractor.h feature_extractor.cc simple_gesture.cc $(CXX)$(INCLUDE)$(CFLAGS)$(GL_FLAGS)$? -o $ @ $(LIBS)$(FREE_LIBS)$(GL_LIBS)
答案 0 :(得分:1)
显然, simple_gesture.cc 取决于 FeatureExtractor 类中的某些功能。因此,您应该考虑将 feature_extractor.o 关联到 simple_gesture 。
答案 1 :(得分: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 $@ $(LIBS) $(FREE_LIBS) $(GL_LIBS) $<
simple_gesture: simple_gesture.o feature_extractor.o
$(CXX) $(GL_FLAGS) -o $@ $(LIBS) $(FREE_LIBS) $(GL_LIBS) $<
%.o: %.cc
$(CXX) -c $(CFLAGS) -o $@ $<
clean:
rm -rf *.o feature_extractor simple_gesture