azinos
azinos

Reputation: 11

Simple Makefile problem

I'm trying to compile a project that uses 2 .cc files and a .h

I'm writing a Makefile but it's not compiling, I get an error:

 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

The Makefile is this:

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

I think I'm not linking well the files..

Any idea?

[edit] solved

it was enough:

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

Upvotes: 1

Views: 681

Answers (2)

florin
florin

Reputation: 14326

You need to make the binaries depend on the presence of the object files, not on the source files. You already have a rule for turning the source into an object.

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

Upvotes: 0

user332325
user332325

Reputation:

Apparently your simple_gesture.cc depends on some function from FeatureExtractor class. So you should consider linking feature_extractor.o into your simple_gesture.

Upvotes: 1

Related Questions