Why does changing the order of build arguments matter?

asked 2016-08-18 11:14:40 -0500

benn gravatar image

updated 2016-08-18 11:16:19 -0500

I've been struggling with a simple hello-world style opencv application in c++, and while it compiles fine, it wouldn't link due to unresolved references to any cv function (OutputArray, waitKey, etc)

From what I've read,


the problem seemed to be a difference between how OpenCV was originally built on the VM, and how my application is being built

The VM I'm using is
https://github.com/razius/ppy-opencv-vagrant  (Ubuntu 14.04.5 / OpenCV 2.4.13))

I WAS trying to build the application this way,

g++ -O2 `pkg-config --cflags --libs opencv` test.cpp -o test.out

but changing it to this, the linker suddenly builds fine:

g++ -O2 -o test.out test.cpp `pkg-config opencv --cflags --libs`

What is happening differently that makes it work?

edit retag flag offensive close merge delete


Simply said, you first need to compile, before you can check if it links correctly. For that you need to correct order of flags. This is a compiler issue and has nothing to do with OpenCV ...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-08-23 09:00:20 -0500 )edit