0

The Exception is here:

g++ -L/usr/local/lib -I./include -I. -lopencv_core -lopencv_highgui -lopencv_imgproc main.o ColorTransfer.o
main.o: In function `showImg(std::string, cv::Mat, int)':
main.cpp:(.text+0x21): undefined reference to `cv::namedWindow(std::string const&, int)'
main.cpp:(.text+0x34): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
main.cpp:(.text+0x75): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
main.cpp:(.text+0x9d): undefined reference to `cv::waitKey(int)'
main.o: In function `main':

And the Makefile is here:

CC=g++
FLAGS=-L./lib -I./include -I. -lopencv_core -lopencv_highgui -lopencv_imgproc

all: ColorTransfer

ColorTransfer: main.o ColorTransfer.o
    $(CC) $(FLAGS) main.o ColorTransfer.o -o ColorTransfer

main.o: main.cpp 
    $(CC) $(FLAGS) -c main.cpp -o main.o

ColorTransfer.o: ColorTransfer.cpp ColorTransfer.h
    $(CC) $(FLAGS) -c ColorTransfer.cpp -o ColorTransfer.o

clean :
    rm -rf main.o ColorTransfer.o

And current directory contains directory named lib, which has opencv libraries.

Cœur
  • 37,241
  • 25
  • 195
  • 267
cstur4
  • 966
  • 2
  • 8
  • 21
  • `make` is doing what you *incorrectly* asked it to do. But `g++` is wrongly invoked in your `Makefile`; it is not `make` but `g++` which does not find libraries... – Basile Starynkevitch Dec 12 '13 at 18:01

2 Answers2

0

In your folder:

 /lib

You have to be sure that there are:

 opencv_core.so
 opencv_highgui.so
 opencv_imgproc.so

And that your LD_LIBRARY_PATH point to this folder. Otherwise, you've to export it:

export LD_LIBRARY_PATH=/lib

Have you download opencv sources or precompiled? Have you configured dynamic linker run-time bindings?

sudo ldconfig

edit

Otherwise, try to check out this soloution!

Community
  • 1
  • 1
Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146
  • Thanks. yes, I have already run the code using IDE(Eclipse+CDT), but I want to compile code using Makefile. And I tried your suggestion, but it also not works. – cstur4 Dec 11 '13 at 11:42
0

You really should pay attention to the order of arguments to g++ ; it matters a lot (libraries should go last in good order - highest level to lowest level).

Use  make -p to learn about rules known to make.... Then improve your Makefile as follow

 CXX=g++
 CXXFLAGS= -I./include -I. -g -Wall
 LDLIBS= -L./lib -lopencv_core -lopencv_highgui -lopencv_imgproc

 all: ColorTransfer

 ColorTransfer: main.o ColorTransfer.o
           $(LINK.cc)  $^ $(LDLIBS) -o $@

 # etc....

I leave you to correct the other lines of your Makefile ... See also this answer ...

I corrected my make rules above : $^ has to be before $(LDLIBS) !

BTW, remake is a nice tool to debug Makefile-s; for instance, with remake -x

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547