Ask Your Question

Undefined symbols cv::_OutputArray::_OutputArray(std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)

asked 2013-12-19 19:19:41 -0500

tigakub gravatar image

Hi everyone. I've been trying to incorporate OpenCV into a Kinect project I have going on OS X Mountain Lion (Xcode 4.6, OpenCV 2.4.7).

Everything seemed to be going fine until I tried calling cv::calibrateCamera, which seems to require output args of class OutputArrayOfArrays. In the examples I see that references to std::vector<cv::mat> are passed in. The code compiles fine, but fails on the link with the following error:

Undefined symbols for architecture x86_64:  
  "cv::_OutputArray::_OutputArray(std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)"

I've read that such errors might be because of a discrepancy between the c++ library against which the opencv libraries are linked and that against which the app code is linked. I've tried switching to libstdc++ in Xcode, and that seems to generate a whole slew of other errors which lead me to think that opencv 2.4.7 was updated with c++11 in mind?

So, just in case, I went back and reconfigured the opencv build with the following.

cmake -D CMAKE_CXX_COMPILER=/Applications/ -D CMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++" -D LLVM_ENABLE_CXX11=ON -D CMAKE_SHARED_LINKER_FLAGS="-lc++"

Unfortunately, I'm still getting the linker error. I don't think it's because I'm missing a library because this is a template invocation, so the code is generated at compile time, no? The code that seems to be causing the problem is as follows.

vector<cv::Mat> rVecs, tVecs;
double tResult = cv::calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rVecs, tVecs, flag);

Is there something wrong with my syntax? Am I missing some kind of typename qualifier or something?

I've been banging my head against this for a couple of days now and would deeply appreciate any insight anyone may have.


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-12-21 13:45:42 -0500

jensenb gravatar image

The missing symbol error you receive is indicative of a mismatch between the c++ library that OpenCV was built with, and the one you are using for your application. More specifically, it looks like OpenCV was compiled with libstdc++ whereas your app seems to be using libc++, indicated by the missing OpenCV symbols involving the std::__1 namespace. Libc++ and libstdc++ have incompatible implementations of some c++ standard types, and so libc++ uses the inline namespace std::__1 to avoid accidentally mixing code compiled with libstdc++ (and whose interfaces use c++ standard types) with incompatible c++ type implementations from libc++.

I suggest recompiling your code with libstdc++ (CMAKE_CXXFLAGS="-stdlib=libstdc++", but this may not even be necessary), which is the default for Mountian Lion. Also I am unsure as to the c++11 compliance of OpenCV at the moment, so I would leave those flags out. The CMAKE_SHARED_LINKER_FLAGS is unnecessary when you are setting "-stdlib=" in CMAKE_CXXFLAGS. If this does not help, then you should post the error message when linking with libstdc++.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2013-12-19 19:19:41 -0500

Seen: 1,848 times

Last updated: Dec 21 '13