-3

I installed opencv using homebrew. I am trying to build a project by linking to opencv. However, I got the following error.

Undefined symbols for architecture x86_64: "cv::FileStorage::FileStorage(std::__1::basic_string, std::__1::allocator > const&, int, std::__1::basic_string, std::__1::allocator > const&)", referenced from: kmeans_save(_VlKMeans const*) in imall.cpp.o kmeans_read() in imall.cpp.o learn_codebook(std::__1::basic_string, std::__1::allocator >) in imall.cpp.o encoding(std::__1::basic_string, std::__1::allocator >) in imall.cpp.o "cv::write(cv::FileStorage&, std::__1::basic_string, std::__1::allocator > const&, cv::Mat const&)", referenced from: cv::FileStorage& cv::operator<< >(cv::FileStorage&, cv::Mat_ const&) in imall.cpp.o cv::FileStorage& cv::operator<< >(cv::FileStorage&, cv::Mat_ const&) in imall.cpp.o "cv::write(cv::FileStorage&, std::__1::basic_string, std::__1::allocator > const&, float)", referenced from: cv::FileStorage& cv::operator<<(cv::FileStorage&, float const&) in imall.cpp.o "cv::write(cv::FileStorage&, std::__1::basic_string, std::__1::allocator > const&, int)", referenced from: cv::FileStorage& cv::operator<<(cv::FileStorage&, int const&) in imall.cpp.o "cv::imread(std::__1::basic_string, std::__1::allocator > const&, int)", referenced from: learn_codebook(std::__1::basic_string, std::__1::allocator >) in imall.cpp.o encoding(std::__1::basic_string, std::__1::allocator >) in imall.cpp.o "cv::Exception::Exception(int, std::__1::basic_string, std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator > const&, int)", referenced from: cv::FileStorage& cv::operator<<(cv::FileStorage&, int const&) in imall.cpp.o cv::FileStorage& cv::operator<<(cv::FileStorage&, float const&) in imall.cpp.o cv::FileStorage& cv::operator<< >(cv::FileStorage&, cv::Mat_ const&) in imall.cpp.o cv::FileStorage& cv::operator<< >(cv::FileStorage&, cv::Mat_ const&) in imall.cpp.o "cv::operator<<(cv::FileStorage&, std::__1::basic_string, std::__1::allocator > const&)", referenced from: cv::operator<<(cv::FileStorage&, char const*) in imall.cpp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am not sure how to fix it. Thanks.

user2547081
  • 189
  • 2
  • 8
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Aurelius Jul 09 '14 at 17:33
  • I doubt it is the issue related to Mavericks, since it could be built in windows. That's why I ask here. – user2547081 Jul 10 '14 at 04:28
  • Solved it by installing opencv with macport instead of homebrew. It should be related to the c++ library that homebrew used to install opencv, since in Mavericks used libc++ (if I remembered correctly). Hopefully, it will be helpful for others. – user2547081 Jul 10 '14 at 05:01

1 Answers1

0

I got very similar errors today with my CUDA-enabled OpenCV built from Homebrew. Apparently the Homebrew formula builds against libstdc++ if you enable CUDA, instead of the now default libc++ from clang. Therefore you must build your program using "-stdlib=libstdc++" to avoid all these errors.