s123
s123

Reputation: 471

Need help setting up OpenCV on a Mac

I'm a beginner programmer so may have missed something obvious here. I'm following this tutorial to set up opencv on my Mac: OpenCV Linux Install (Yes it's the linux version, but it's supposed to work with Mac) I've followed all directions, and everything worked correctly. ( I did CMake, make, and sudo make install with no errors)

However, when I compile, I get errors saying the compiler cannot find the header files. Example:

fatal error: ' opencv2\opencv.hpp ' file not found
#include < opencv2\opencv.hpp > 

I'm guessing I did not yet link my installation or maybe "set the path"? However, that was not in the directions. Any ideas?

Upvotes: 0

Views: 653

Answers (1)

Antonio
Antonio

Reputation: 20266

After some trial and error iterations, it looks your compiler line should be:

g++ -I/usr/local/include -lopencv_core -lopencv_imgproc -lopencv_highgui -L/usr/local/lib/ main.cpp main.cpp

Namely you should check your install_manifest.txt (resume of your opencv installation command, available in the opencv build directory) and add the options:

  • -I<path to the include directory>
  • -l<name of the library file to be linked, removing "lib" prefix and any extension> (repeat for as many libraries you need to link to)
  • -L<path to the library directory>

For your system, the library files can be distinguished as having extension .dylib (and prefix lib). In Windows the extension would be .dll and for Unix .so (for dynamic libraries, while static libraries have extension .lib and .a respectively)

Upvotes: 1

Related Questions