Ask Your Question

headupinclouds's profile - activity

2018-04-25 13:28:10 -0500 received badge  Famous Question (source)
2017-06-27 02:06:29 -0500 received badge  Taxonomist
2015-07-17 13:41:37 -0500 received badge  Notable Question (source)
2014-10-30 03:21:06 -0500 received badge  Popular Question (source)
2014-08-22 19:22:12 -0500 received badge  Popular Question (source)
2014-02-08 14:55:05 -0500 asked a question Include opencv2.framework in CMake iOS project with find_library

I'm trying to include opencv2.framework in my CMake iOS project using the standard Xcode generator. I've verified that my opencv2.framework works as expected when included in an Xcode generated project. The CMake generated Xcode project compiles, and the target app runs fine. I haven't been able to find the correct syntax to include the opencv2.framework in order to start using OpenCV sections of code, nor have I found any references for how to achieve this. I'm even able to include Apple's standard system frameworks in my app using a macro based on find_library, so I can't be too far off. This is admittedly a bit more of a CMake question, but I think there is enough overlap and interest to warrant an opencv workflow related question here, and my previous post to the CMake mailing list has gone unanswered. I expect there are more CMake + opencv2 users on this forum. This post contains fairly specific details regarding what I have tried, but I'll be happy with any solution.

Update: I'm able include the opencv2.framework using find_library if I place it in the Xcode internal folder Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/opencv2.framework (I've created a new post and updated the link above to provide more details).

2012-11-15 08:23:18 -0500 received badge  Student (source)
2012-11-13 09:46:30 -0500 asked a question cmake install_name_tool absolute path for library on Mac OSX

When I compile OpenCV for Mac OSX 10.8 using XCode 4.5.2 and cmake 2.8.9 my installed libraries aren't configured with the correct corresponding installation path.

cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=RELEASE -D WITH_QT=ON -D WITH_OPENGL=ON -DCMAKE_INSTALL_PREFIX=/opt/local ../opencv.ram/

The CMAKE_INSTALL_PREFIX=/opt/local puts the libraries in the correct place after a "make install" but the embedded path names are configured with a relative path name such as "lib/libopencv" and not "/opt/local/lib/libopencv" as desired.

otool -D /opt/local/lib/libopencv_core.2.4.3.dylib /opt/local/lib/libopencv_core.2.4.3.dylib: lib/libopencv_core.2.4.dylib

The libraries in the build location after the make command but before the "make install" are configured with the correct absolute path name corresponding to the build tree location:

otool -D /Volumes/ramdisk/osx_ffmpeg/lib/libopencv_core.2.4.3.dylib /Volumes/ramdisk/osx_ffmpeg/lib/libopencv_core.2.4.3.dylib: /Volumes/ramdisk/osx_ffmpeg/lib/libopencv_core.2.4.dylib

The relative path seems to be set during installation in the generated cmake_install.cmake file via the install_name_tool command as shown here.

grep -C1 install_name /Volumes/ramdisk/osx_ffmpeg/modules/core/cmake_install.cmake NOT IS_SYMLINK "${file}") EXECUTE_PROCESS(COMMAND "/usr/bin/install_name_tool" -id "lib/libopencv_core.2.4.dylib"

Basically I'd like to configure the installed libraries with correct embedded absolute path names, so that I can link to them directly without using DYLD_LIBRARY_PATH or the like. Presumably this is the desired default build behavior? Perhaps my build syntax is missing something.

I have found a number of links to folks who have remedied this with post installation scripts using the install_name_tool command to modify the path names, such as shown in the link below, but I'm guessing there is a way to avoid this.

install_name_tool -id pwd/opencv/lib/libopencv_core.2.1.dylib opencv/lib/libopencv_core.2.1.dylib

http://alufr-ros-pkg.googlecode.com/svn-history/r1049/branches/student-projects/bsc-project-ws1011/faceedge/glimageviewer/change_install_names_for_mac

If I omit the CMAKE_INSTALL_PREFIX=/opt/local cmake option the libraries are installed in the default /usr/local/lib location but still have a relative embedded path name.

UPDATE: I haven't found a cmake fix for this but did create a simpler post installation bash script that should fix the install path for opencv libraries and their dependencies:

CV_LIB_PATH=/opt/local/lib
find ${CV_LIB_PATH} -type f -name "libopencv*.dylib" -print0 | while IFS="" read -r -d "" dylibpath; do
   echo install_name_tool -id "$dylibpath" "$dylibpath"
   install_name_tool -id "$dylibpath" "$dylibpath"
   otool -L $dylibpath | grep libopencv | tr -d ':' | while read -a libs ; do
       [ "${file}" != "${libs[0]}" ] && install_name_tool -change ${libs[0]} ${CV_LIB_PATH}/`basename ${libs[0]}` $dylibpath
   done
done
2012-11-03 14:38:19 -0500 commented question opencv for ios 5.1 (on OS X 10.8) with boost using c++11 and libc++

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.

2012-11-01 17:20:45 -0500 commented answer opencv for ios 5.1 (on OS X 10.8) with boost using c++11 and libc++

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

2012-11-01 17:18:06 -0500 commented answer opencv for ios 5.1 (on OS X 10.8) with boost using c++11 and libc++

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?

2012-11-01 16:20:31 -0500 received badge  Editor (source)
2012-11-01 16:01:05 -0500 asked a question opencv for ios 5.1 (on OS X 10.8) with boost using c++11 and libc++

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>