I try to compile some files from the opencv-2.4.8/apps/haarfinder but i get the following error:
ld: library not found for -llibtbb.dylib
Notic
IOutput is an interface where their methods are declared at ioutput.h and must be implemented somewhere. I found out they were implemented at cvsamplesoutput.cpp so we just need ask gcc to compile that file. For that the correct command should be:
g++ `pkg-config --libs --cflags opencv | sed 's/libtbb\.dylib/tbb/' ` -I. -o mergevec mergevec.cpp cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp cvhaartraining.cpp cvsamplesoutput.cpp -lopencv_core -lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
I installed opencv 2.4.12 with tbb from homebrew on El Capitan, and then separately downloaded the source from github in order to compile mergevec and the s/libtbb\.dylib/tbb/
fix on its own still didn't help.
My fix was to add -L/usr/local/lib
to the start of the g++ arguments as by default it wasn't searching for my homebrew libs. I also had to add cvsamplesoutput.cpp
as mentioned in another answer to fix the following error:
Undefined symbols for architecture x86_64:
"IOutput::createOutput(char const*, IOutput::OutputType)", referenced from:
JpgDatasetGenerator::JpgDatasetGenerator(char const*) in cvhaartraining-8f5a1b.o
PngDatasetGenerator::PngDatasetGenerator(char const*) in cvhaartraining-8f5a1b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The final command that worked for me was:
g++ -L/usr/local/lib `pkg-config --libs --cflags opencv | sed 's/libtbb\.dylib/tbb/'`\
-I. -o mergevec mergevec.cpp cvboost.cpp cvcommon.cpp cvsamples.cpp\
cvhaarclassifier.cpp cvhaartraining.cpp cvsamplesoutput.cpp -lopencv_core\
-lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
Old question, but I needed it, or rather I found this better solution - and this may help other searchers.
Follow the instructions in the github description, rather than that blog post: https://github.com/mrnugget/opencv-haar-classifier-training
This corrects the spelling error in the command line:
g++ `pkg-config --libs --cflags opencv | sed 's/libtbb\.dylib/tbb/'`\
-I. -o mergevec mergevec.cpp\
cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp\
cvhaartraining.cpp\
-lopencv_core -lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
If the libtbb.dylib
file already exists like in my case in the /usr/local/lib
folder then all you need to do is to run this command:
export DYLD_LIBRARY_PATH=/usr/local/lib
Suppose libtbb.dylib
is in /usr/local/lib/libtbb.dylib
and opencv.pc
is in /usr/local/lib/pkgconfig
(The location may vary depending on where you install tbb
and pkg-config
)
Then edit /usr/local/lib/pkgconfig/opencv.pc
, change -llibtbb.dylib
to /usr/local/lib/libtbb.dylib