Ask Your Question
0

opencv for ios 5.1 (on OS X 10.8) with boost using c++11 and libc++

asked 2012-11-01 16:01:05 -0600

headupinclouds gravatar image

updated 2012-11-01 16:20:31 -0600

In the process of adding boost 1.5.1 to my ios project, I encountered an incompatibility due to C++ Standard Library conflicts, e.g.:

Undefined symbols for architecture armv7:  "std::__1::locale::use_facet(std::__1::locale::id&) const"

since my boost build via galbraithjosephs-boostoniphone compiles with the following options:

-DBOOST_AC_USE_PTHREADS -DBOOST_SP_USE_PTHREADS -std=c++11 -stdlib=libc++

and it appears that the OpenCV 2.4.9 CMake build compiles with gnu++11 and libstdc++. I'm compiling an OpenCV framework with the included build script as follows:

python2.7 opencv/ios/build_framework.py ios

At this point my plan is to try to rebuild my OpenCV framework with the c++11 compiler and libc++ standard library as in the boost build, and then update all of my XCode libraries and applications appropriately.

The following link aimed at OpenCV 2.4.2 OpenCV with C++11 on OS X 10.8 seems to be a good starting point, and it essentially suggests modifying CMakeLists.txt with the following entries:

 message("Setting up Xcode for C++11 with libc++.")
 set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x")
 set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")

but after modifying the opencv/CMakeLists.txt file in the first step my build fails with the following message:

/Volumes/ramdisk/opencv/modules/core/src/arithm.cpp:444:51: error: constant expression evaluates to 4294967295 which cannot be narrowed to type 'int' [-Wc++11-narrowing]
static int CV_DECL_ALIGNED(16) v64f_absmask[] = { 0xffffffff, 0x7fffffff, 0xffffffff, 0x7fffffff };

and I noticed that the output indicates that it is still using the GNU compiler. I see the message added above in the build output

Setting up Xcode for C++11 with libc++.

but the compiler and arguments are still listed as:

-- General configuration for OpenCV 2.4.9 =====================================
-- 
--   Platform:
--     Host:                        Darwin 12.0.0 i386
--     Target:                      iOS
--     CMake:                       2.8.9
--     CMake generator:             Xcode
--     CMake build tool:            /opt/local/bin/cmakexbuild
--     Xcode:                       4.4.1
-- 
--   C/C++:
--     Built as dynamic libs?:      NO
--     C++ Compiler:                /usr/bin/g++
--     C++ flags (Release):         -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden   -Wno-c++11-narrowing -DNDEBUG -O3 -fomit-frame-pointer -ffast-math 
--     C++ flags (Debug):           -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden   -Wno-c++11-narrowing  
--     C Compiler:                  /usr/bin/gcc
--     C flags (Release):           
--     C flags (Debug):             
--     Linker flags (Release):      
--     Linker flags (Debug):        
--     Precompiled headers:         NO
--

If anyone has advice or a link for how to tune CMake accordingly it would be much appreciated. I would imagine opencv + boost are fairly common siblings for ios platforms.

EDIT: The build also reports a second error

/Volumes/ramdisk/opencv/modules/core/include/opencv2/core/operations.hpp:65:16: fatal error: 'ext/atomicity.h' file not found
      #include <ext/atomicity.h>
edit retag flag offensive close merge delete

Comments

The latest version # seems to be different for the two repositories sited on http://code.opencv.org/projects/opencv/wiki (that page suggests itseez is a mirror): (1) git://code.opencv.org/opencv.git => 2.4.9 grep -E "CV_.*_VERSION" ${OPENCV}/opencv/modules/core/include/opencv2/core/version.hpp

define CV_MAJOR_VERSION 2

define CV_MINOR_VERSION 4

define CV_SUBMINOR_VERSION 9

(2) git://github.com/itseez/opencv.git => 2.4.3 grep -E "CV_.*_VERSION" ${ITSEEZ}/opencv/modules/core/include/opencv2/core/version.hpp

define CV_MAJOR_VERSION 2

define CV_MINOR_VERSION 4

define CV_SUBMINOR_VERSION 3

Can someone explain or send a link that explains the difference between and reason for the two repositories? I'm guessing this is addressed somewhere but my searches have come up empty.

headupinclouds gravatar imageheadupinclouds ( 2012-11-03 14:38:19 -0600 )edit

2 answers

Sort by » oldest newest most voted
0

answered 2012-11-01 16:45:06 -0600

AlexanderShishkov gravatar image

Previously we used gcc compiler and libstd++ for OpenCV iOS framework. So you should comment the following strings for using clang compiler:

CMAKE_FORCE_C_COMPILER (gcc gcc)
CMAKE_FORCE_CXX_COMPILER (g++ g++)

in the both toolchain files (e.g. https://github.com/Itseez/opencv/blob/master/ios/cmake/Toolchains/Toolchain-iPhoneOS_Xcode.cmake).

Or you can download the latest OpenCV code. Today we updated it for using clang compiler and libc++. The second problem with atomicity was fixed too(https://github.com/Itseez/opencv/pull/126).

edit flag offensive delete link more

Comments

Magic! I've been hacking this all day. The latest OpenCV should be fine. I'll give that a try. Thanks.

EDIT: From the link it seems that you removed the atomicity.h dependency in commit # d9d4e8df6f8d26e904ac3c50a54df1d5e1c6cecd but after a fresh checkout via

git clone git://github.com/Itseez/opencv.git

my opencv/modules/core/include/opencv2/core/operations.hpp still contains a #include <ext/atomicity.h>. I'm not a git user, so perhaps I'm missing something?

headupinclouds gravatar imageheadupinclouds ( 2012-11-01 17:18:06 -0600 )edit

Try to use 2.4 branch.

AlexanderShishkov gravatar imageAlexanderShishkov ( 2012-11-05 05:15:08 -0600 )edit
0

answered 2012-11-01 16:33:43 -0600

cr333 gravatar image

The warning you’re getting looks like a clang warning. The way I see it, is that the CMAKE_XCODE_ATTRIBUTE_* override the compiler and standard library only inside of XCode, without making CMake aware of this, which is why it says it uses gcc/g++ as compilers. So C++11 should be working alright with libc++.

Next, you should try to fix the compilation error you get. The simplest fix appears to be to change the "int" to "unsigned int" in the hope that this doesn't break anything.

PS: The latest released version of OpenCV is 2.4.2 – what’s this version 2.4.9 you have?

edit flag offensive delete link more

Comments

That was the version of my last checkout from the git repository

headupinclouds gravatar imageheadupinclouds ( 2012-11-01 17:20:45 -0600 )edit

Question Tools

Stats

Asked: 2012-11-01 16:01:05 -0600

Seen: 2,904 times

Last updated: Nov 01 '12