5

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:

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.

Community
  • 1
  • 1
mikewoz
  • 146
  • 2
  • 9

2 Answers2

10

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.

foundry
  • 31,615
  • 9
  • 90
  • 125
1

I am also working on a project using OpenCV and a 3rd party library which requires libstdc++.

As I just ran into this problem myself, I wanted to share what worked for me.


I was able to get OpenCV working by adding "libc++.dylib" to my project.

Build Phases -> "Link Binary with Libraries" -> "+" -> libc++.dylib

For reference, I am using OpenCV 2.4.9 (opencv-2.4.9) from opencv.org. I compiled it using the ios platform build_framework.py per the instructions in OpenCV's docs. No modification necessary.