R.J.
R.J.

Reputation: 1503

Linking to OpenCV under MacOSX

I'm trying to compile a C++/OpenCV Code in MacOS X Snow Leopard which was originally under Linux. I installed OpenCV 2.2 using MacPorts, but I cannot use something like this anymore:

g++ -o Localization Localization.o DataReader.o Kalman.o -libopencv_core -libopencv_highgui -L/usr/local/lib/

I'm getting this error:

ld: library not found for -libopencv_core
collect2: ld returned 1 exit status
make: *** [Localization] Error 1

I tried other variations; like -lcv, -lhighgui which I originally used to use, but I'm not sure what to use here.

Upvotes: 1

Views: 4298

Answers (2)

Tilman Vogel
Tilman Vogel

Reputation: 9773

The link flag should be -lopencv_core not -libopencv_core. The latter will look for a file called libibopencv_core.{dylib,a} instead of libopencv_core.{dylib,a}. The same for opencv_highgui.

Upvotes: 2

etarion
etarion

Reputation: 17131

If you're using macports, you're using the wrong paths. It should be -L/opt/local/lib, not /usr/local. Also, to make things easier, you should just use pkg-config:

g++ -o Localization Localization.o DataReader.o Kalman.o $(pkg-config --libs opencv)

(that assumes that you have /opt/local/bin in your PATH). This way you can use the same line for linux and OS X.

Upvotes: 3

Related Questions