0

When I build a hellworld opencv application, I got "undefined refernce" for about every function I would use. The build command is

g++ `pkg-config opencv --cflags --libs` samples/hello.cpp 

Then the issue is fixed by moving the source file to the first parameter

g++ samples/hello.cpp `pkg-config opencv --cflags --libs`

Why is that?

FYI, g++ version

g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
ROTOGG
  • 1,106
  • 1
  • 7
  • 17
  • Because the libs should be always at the end. The compiler will try to compile all the modules and saves the undefined references, when it gets to the end, it searches the references in libraries, if the libs are at the beginning, compiler searches them first with no interest. – Croolman May 02 '17 at 11:16
  • thanks! the explanation makes sense. – ROTOGG May 02 '17 at 12:37

0 Answers0