Writing makefile for a c++ project

Hi all, I'm Andrea, an Italian student of computer science.
I need to run a project in a server via ssh, so I need to write a makefile (I working on Eclipse now).
I'm looking for it in the net, but I don't find what I need.
I write this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
OBJS = Elaborato.o Image.o Reader.o Slice.o
CXX = g++
DEBUG = -g
CXXFLAGS = -O0 -g3 -Wall -c $(DEBUG) -fmessage-length=0
LFLAGS = -Wall $(DEBUG)
LIBS = -I/usr/local/include/opencv -L/usr/local/lib -L/usr/local/bin -lcv -lcxcore -lhighgui -lcvaux 
	
ElaboratoTBD : $(OBJS)
	$(CXX) $(LFLAGS) -o ElaboratoTBD $(OBJS)

Elaborato.o : Elaborato.cpp Image.h Reader.h Slice.h
	$(CXX) $(CXXFLAGS) Elaborato.cpp
	
Image.o : Image.cpp Image.h Slice.h
	$(CXX) $(CXXFLAGS) Image.cpp
	
Reader.o : Reader.cpp Reader.h Slice.h Image.h
	$(CXX) $(CXXFLAGS) Reader.cpp
	
Slice.o : Slice.cpp Slice.h
	$(CXX) $(CXXFLAGS) Slice.cpp
	
clean:
	\rm *.o *~ pl


Libs address are correct, even the dependeces, but when I run make I have these errors:
guess85:cartella guess$ make
g++ -00 -g3 -Wall -c -g -fmessage-length=0 Elaborato.cpp
Elaborato.cpp:9:16: error: cv.h: No such file or directory
Elaborato.cpp:10:21: error: highgui.h: No such file or directory
Slice.h:32: error: ISO C++ forbids declaration of ‘IplImage’ with no type
Slice.h:32: error: expected ‘;’ before ‘*’ token
Slice.h:33: error: ISO C++ forbids declaration of ‘IplImage’ with no type
Slice.h:33: error: expected ‘;’ before ‘*’ token
Slice.h:40: error: ISO C++ forbids declaration of ‘vector’ with no type
Slice.h:40: error: expected ‘;’ before ‘<’ token
Slice.h:42: error: ISO C++ forbids declaration of ‘vector’ with no type
Slice.h:42: error: expected ‘;’ before ‘<’ token
Slice.h:44: error: ISO C++ forbids declaration of ‘vector’ with no type
Slice.h:44: error: expected ‘;’ before ‘<’ token
Slice.h:46: error: expected ‘;’ before ‘(’ token
Slice.h:47: error: ‘IplImage’ has not been declared
Slice.h:50: error: ‘vector’ has not been declared
Slice.h:50: error: expected ‘,’ or ‘...’ before ‘<’ token
Slice.h:52: error: ‘IplImage’ has not been declared
Slice.h:52: error: ‘vector’ has not been declared
Slice.h:52: error: expected ‘,’ or ‘...’ before ‘<’ token
Slice.h:53: error: ISO C++ forbids declaration of ‘IplImage’ with no type
Slice.h:53: error: expected ‘;’ before ‘*’ token
Slice.h:57: error: expected `)' before ‘*’ token
Image.h:30: error: ISO C++ forbids declaration of ‘IplImage’ with no type
Image.h:30: error: expected ‘;’ before ‘*’ token
Image.h:34: error: ISO C++ forbids declaration of ‘vector’ with no type
Image.h:34: error: expected ‘;’ before ‘<’ token
Image.h:36: error: ISO C++ forbids declaration of ‘IplImage’ with no type
Image.h:36: error: expected ‘;’ before ‘*’ token
Image.h:37: error: expected ‘;’ before ‘(’ token
Image.h:39: error: ‘vector’ has not been declared
Image.h:39: error: expected ‘,’ or ‘...’ before ‘<’ token
Reader.h:24: error: ISO C++ forbids declaration of ‘vector’ with no type
Reader.h:24: error: expected ‘;’ before ‘<’ token
Reader.h:25: error: ISO C++ forbids declaration of ‘vector’ with no type
Reader.h:25: error: expected ‘;’ before ‘<’ token
Reader.h:33: error: ISO C++ forbids declaration of ‘vector’ with no type
Reader.h:33: error: expected ‘;’ before ‘<’ token
make: *** [Elaborato.o] Error 1

What is wrong? I'm new in writing makefile and I'm sure that I make some errors.
Thanks to all.
When compiling the individual object files, the compiler needs the include path specified in LIBS.
I modifide makefile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
OBJS = Elaborato.o Image.o Reader.o Slice.o
CXX = g++
DEBUG = -g
CXXFLAGS = -O0 -g3 -Wall -c $(DEBUG) -fmessage-length=0
LFLAGS = -Wall $(DEBUG)
LIBS = -I/usr/local/include/opencv -L/usr/local/lib -L/usr/local/bin -lcv -lcxcore -lhighgui -lcvaux 
	
ElaboratoTBD : $(OBJS)
	$(CXX) $(LFLAGS) -o ElaboratoTBD $(OBJS)

Elaborato.o : Elaborato.cpp Image.h Reader.h Slice.h
	$(CXX) $(CXXFLAGS) $(LIBS) Elaborato.cpp
	
Image.o : Image.cpp Image.h Slice.h
	$(CXX) $(CXXFLAGS) $(LIBS) Image.cpp
	
Reader.o : Reader.cpp Reader.h Slice.h Image.h
	$(CXX) $(CXXFLAGS) $(LIBS) Reader.cpp
	
Slice.o : Slice.cpp Slice.h
	$(CXX) $(CXXFLAGS) $(LIBS) Slice.cpp
	
clean:
	\rm *.o *~ pl

And now I have another error:(

guess85:cartella guess$ make
g++ -O0 -g3 -Wall -c -g -fmessage-length=0 -I/usr/local/include/opencv -L/usr/local/lib -L/usr/local/bin -lcv -lcxcore -lhighgui -lcvaux  Elaborato.cpp
i686-apple-darwin9-g++-4.0.1: -lcv: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lcxcore: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lhighgui: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lcvaux: linker input file unused because linking not done
g++ -O0 -g3 -Wall -c -g -fmessage-length=0 -I/usr/local/include/opencv -L/usr/local/lib -L/usr/local/bin -lcv -lcxcore -lhighgui -lcvaux  Image.cpp
i686-apple-darwin9-g++-4.0.1: -lcv: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lcxcore: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lhighgui: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lcvaux: linker input file unused because linking not done
g++ -O0 -g3 -Wall -c -g -fmessage-length=0 -I/usr/local/include/opencv -L/usr/local/lib -L/usr/local/bin -lcv -lcxcore -lhighgui -lcvaux  Reader.cpp
i686-apple-darwin9-g++-4.0.1: -lcv: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lcxcore: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lhighgui: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lcvaux: linker input file unused because linking not done
g++ -O0 -g3 -Wall -c -g -fmessage-length=0 -I/usr/local/include/opencv -L/usr/local/lib -L/usr/local/bin -lcv -lcxcore -lhighgui -lcvaux  Slice.cpp
Slice.cpp: In member function ‘void Slice::columnAnalyis()’:
Slice.cpp:487: warning: unused variable ‘mediaMin’
Slice.cpp:488: warning: unused variable ‘numMin’
Slice.cpp:489: warning: unused variable ‘numMax’
i686-apple-darwin9-g++-4.0.1: -lcv: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lcxcore: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lhighgui: linker input file unused because linking not done
i686-apple-darwin9-g++-4.0.1: -lcvaux: linker input file unused because linking not done
g++ -Wall -g -o ElaboratoTBD Elaborato.o Image.o Reader.o Slice.o
Undefined symbols:
  "_cvSaveImage", referenced from:
      Image::crop(int)  in Image.o
      Slice::fillHist()     in Slice.o
      Slice::crop(_IplImage*, int, int)in Slice.o
      Slice::separateColumn()      in Slice.o
  "_cvShowImage", referenced from:
      Slice::show()     in Slice.o
  "_cvWaitKey", referenced from:
      Slice::show()     in Slice.o
  "_cvThreshold", referenced from:
      Image::Image(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::vector<_IplImage*, std::allocator<_IplImage*> >*)in Image.o
  "_cvLoadImage", referenced from:
      Image::Image(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::vector<_IplImage*, std::allocator<_IplImage*> >*)in Image.o
  "_cvCreateImage", referenced from:
      Image::crop(int)  in Image.o
      Slice::Slice(_IplImage*, std::vector<_IplImage*, std::allocator<_IplImage*> >*)in Slice.o
      Slice::crop(_IplImage*, int, int)in Slice.o
      Slice::separateColumn()      in Slice.o
      Slice::separateColumn()      in Slice.o
  "_cvAdaptiveThreshold", referenced from:
      Image::Image(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::vector<_IplImage*, std::allocator<_IplImage*> >*)in Image.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [ElaboratoTBD] Error 1

Why "linker input file unused because linking not done"?
You're specifying the libs when compiling, but the compiler doesn't need them. It just needs the include path.
The linker however needs the libs, but not the include path. You need to add LIBS to the final linking step.
Thanks, I separate include path and libs and now working good!
Topic archived. No new replies allowed.