Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 setting 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.

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 setting 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.

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