Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Unresolved symbols - name mangling mismatch - xcode

I built the i386 flavor of OpenCV locally on my Macbook running Lion, by using

cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 -D CMAKE_C_FLAGS=-m32 -D CMAKE_CXX_FLAGS=-m32 ..
make -j8
sudo make install

Libraries built and published fine, and I've added them to my xcode project. However, there are link errors when building my test app, and they seem to be name mangling issues.

Undefined symbols for architecture i386: "cv::namedWindow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from: _main in main.o "cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from: _main in main.o "cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from: _main in main.o

Taking cv::imread as an example, it is exported from libopencv_highgui.dylib with the name:

00007510 (__TEXT,__text) external __ZN2cv6imreadERKSsi 

while main.o is referencing the symbol

U __ZN2cv6imreadERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEi

On the other hand, function __ZN2cv7waitKeyEi from the same dylib links fine.

Both the test app and the framework are for i386 arch.

Any ideas what might be causing this issue?

like image 361
ansh Avatar asked Dec 11 '25 07:12

ansh


1 Answers

I've had the same problem. I think the issue could be that if you have used the MacPorts to compile your OpenCV libraries, they probably got built by the GCC according to it's Portfile. I switched the compiler used in the XCode (Apple LLVM 4.1) to the LLVM GCC 4.2 and now it works.

Hope it helps.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!