Ask Your Question
2

cmake install_name_tool absolute path for library on Mac OSX

asked 2012-11-13 09:46:30 -0600

headupinclouds gravatar image

updated 2012-11-13 11:37:47 -0600

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
edit retag flag offensive close merge delete

Comments

I'm running into the same issue with Qt5 and macdeployqt, which complains about wrong paths (the relative ones mentioned above) to the opencv .dylib. Any update on this? None of the proposed solution here solved the problem. The relative paths are: lib/libopencv_core.3.0.dylib (compatibility version 3.0.0, current version 3.0.0) lib/libopencv_highgui.3.0.dylib (compatibility version 3.0.0, current version 3.0.0) lib/libopencv_imgproc.3.0.dylib (compatibility version 3.0.0, current version 3.0.0)

octopode gravatar imageoctopode ( 2015-12-10 16:32:45 -0600 )edit

A simple solution is cmake -D BUILD_SHARED_LIBS=OFF. Static libraries do not use relative path.

martino gravatar imagemartino ( 2016-04-07 08:30:14 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-01-17 13:02:30 -0600

mbertini gravatar image

here's a small patch you can apply to:

  • cmake/OpenCVModule.cmake
  • apps/traincascades |
  • haartraining/CMakeLists.txt

files that contain INSTALL_NAME_DIR:

change the INSTALL_NAME_DIR lib to INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib In this way the full path to the dynamic libraries will be used

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-11-13 09:46:30 -0600

Seen: 9,963 times

Last updated: Jan 17 '13