Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV 2.4.3+ with libstdc++ for iOS?

I'm trying to include a recent version of OpenCV into an existing iOS project and am having linker errors because my XCode project is set to use libstdc++ and not libc++ / C++ 11 support.

I have seen several other people who have fixed their errors by enabling libc++. Examples:

  • Linker errors after upgrading Xcode to 4.5.2 and OpenCV to 2.4.3
  • How to resolve iOS Link errors with OpenCV

However, I NEED to use libstdc++ because I have other 3rd party libraries which are already compiled with the older stdlib (can't be changed). Is there a way to compile OpenCV 2.4.3+ without -stdlib=libc++ ? Are there special flags to pass to CMake? or to the build_framework.py script that comes in the ios folder of the OpenCV source code?

Alternatively, does anyone have a binary version available? It seems all downloadable from OpenCV assume libc++ / C++11.

like image 203
mikewoz Avatar asked Apr 06 '13 20:04

mikewoz


1 Answers

In the source for openCV locate this file:

ios/cmake/Modules/Platform/iOS.cmake

Change this line:

set (CMAKE_CXX_FLAGS "-stdlib=libc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden")

to:

set (CMAKE_CXX_FLAGS "-stdlib=libstdc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden")

Compile using the python script

ios/build_framework.py

Then you should be good to go

I have just tried this on 2.4.3 source, swapped in the resulting framework on an existing project, changed the C++ standard library for the project to libstdc++ and it runs fine.

like image 109
foundry Avatar answered Oct 22 '22 09:10

foundry