Compiling example on Mac?

Well - this is not in the strictest sense an OpenCV question - but it concerns the examples of OpenCV and how to compile them.

I want to compile the example at

but I am struggling.

I tried g++ -std=c++11 -I /usr/local/Cellar/opencv/4.5.3_2/include/opencv4/ bg_sub.cpp but it failed with “Undefined symbols for architecture x86_64”.

I am on an Intel Mac, running Catalena and OpenCV installed using home-brew.

Any ideas?

apart from finding headers (hey, progress !!)
you need to link to the resp. openv libs, so expand your cmdline with:

-L/usr/local/Cellar/opencv/4.5.3_2/lib -lopencv_core -lopencv_imgproc [... more libs]

(look at the code, you need to add the resp. lib for each opencv header you include)

also, please have a look at the cmake example ,
usually you would rather generate a makefile, instead of fiddling with this manually

1 Like