[vtkusers] How to fix Mac OS X problem of applications not being able to dine dyld libraries

Elvis Dowson elvis.dowson at mac.com
Thu Sep 3 15:50:03 EDT 2009


Hi Andrew,

On Sep 3, 2009, at 11:31 PM, Andrew Wiles wrote:

>
> I have basically got to the same point you did below with the  
> libvtkQtChart library.  Did you ever find a solution?  I can't seem  
> to find any reference to a solution in Google.  I can launch my  
> program from the command line, but I can't use a debugger in XCode  
> or QtCreator.
>

It's been a while and I think I got past that error using Mike  
Jackson's script.

Here is the script, and the entire technote can be found below. See  
step 05 for the appropriate usage to fix the issue with the VTK  
libraries.


#!/bin/bash
# /////////////////////////////////////////////////////////////////////////////
#
#   Copyright (c) 2008, Michael A. Jackson
#   Email:
#   All rights reserved.
#   BSD License: http://www.opensource.org/licenses/bsd-license.html
#
#
# /////////////////////////////////////////////////////////////////////////////


# The first argument is where vtk was installed.
VTK_INSTALL_PREFIX="$1"
#VTK_INSTALL_PREFIX="/Users/Shared/Toolkits/VTK-5.2"

cd $VTK_INSTALL_PREFIX
vtksys=`find "$VTK_INSTALL_PREFIX" -name "libvtksys.dylib"`
#echo "vtksys: $vtksys"
libDirName=`dirname "$vtksys"`
#echo "libDirName: $libDirName"

base=`basename "$VTK_INSTALL_PREFIX"`
curlibdir=`dirname "$vtksys"`
curbase=`basename "$curlibdir"`
confLibDir=""

# echo "base: $base"
# echo "curlibdir: $curlibdir"
# echo "curbase: $curbase"
# echo "confLibDir: $confLibDir"
# echo "----------"
switch=1
while [ "$switch" -ne 0 ]; do
   echo "confLibDir: $confLibDir"
   confLibDir=/$curbase$confLibDir
   curlibdir=`dirname "$curlibdir"`
   curbase=`basename "$curlibdir"`

   # echo "base: $base"
   # echo "curlibdir: $curlibdir"
   # echo "curbase: $curbase"
   # echo "confLibDir: $confLibDir"
   # echo "----------"
   if [ "$base" = "$curbase" ]; then
     switch=0
   fi
done

echo "VTK_INSTALL_PREFIX: $VTK_INSTALL_PREFIX"
DEBUG=1
COPY_BUILD_DIR_FOR_DEBUG=0

TmpDir="/tmp"
LibDirName="$confLibDir"
vtkInstallLibDir="$VTK_INSTALL_PREFIX$LibDirName/"

#echo "remove previous installation libraries at $vtkInstallLibDir"
#rm -rf "$vtkInstallLibDir"

#echo "Creating new lib dir at $vtkInstallLibDir"
#mkdir -p "$vtkInstallLibDir"


# Set up a debugging directory and copy all the libraries into that  
directory.
# then we will fix up there.
if [ "x$COPY_BUILD_DIR_FOR_DEBUG" = "x1" ]; then
   rm -rf "$TmpDir/vtk-test"
   mkdir -p "$TmpDir/vtk-test"
   (cd "$VTK_INSTALL_PREFIX/bin" && tar c${TAR_FLAG}f - *.dylib ) |  
(cd "$TmpDir/vtk-test" && tar xf - )
   VTK_INSTALL_PREFIX=$TmpDir/vtk-test
fi
# -- Skip to the bottem at this point..


#  
-----------------------------------------------------------------------------
#  Conditional Printing
#  
-----------------------------------------------------------------------------
function printStatus()
{
	if [ "x$DEBUG" = "x1" ]; then
	    echo "    ${1}"
	fi
}

#  
-----------------------------------------------------------------------------
#  This function will correct the install_name of an OS X Framwork
#  $1 is the path to a framework
#  $2 is the target file to update
#  
-----------------------------------------------------------------------------
function CorrectLinkedFrameworkInstallName()
{
# This code IS NOT correct any more for this case.
	oldPath="${1}"
	libName=`basename ${oldPath}`
	frameworkName="${libName}.framework"
	frameworkRootDir="${1%${frameworkName}*}"
	frameworkBundle="${frameworkRootDir}${frameworkName}"
	newPath="${InstallNameFramework}${1#${frameworkRootDir}*}"
	install_name_tool -change "${oldPath}" "${newPath}" "${2}"
}

#  
-----------------------------------------------------------------------------
#  uses install_name_tool to correct all the DEPENDENCIES of an input  
file
#  $1 is an install_name to check. This was generated from a call to  
otool -L
#  $2 is the Library in its final installed location
#  
-----------------------------------------------------------------------------
function CorrectLibraryDependency()
{
   # printStatus "        |- CorrectLibraryDependency"
   pattern=" \(*\)"            # everything between ' (' and ')'
   oldPath="${1%$pattern}"
   # Filter out System Libraries or those located in /Libary/Frameworks
   isSystem=`expr  "${oldPath}" : '/System'`
   isUsrLib=`expr "${oldPath}" : '/usr/lib'`
   isEmbeddedPathExe=`expr "${oldPath}" : '@executable_path/'`
   isEmbeddedPathLdr=`expr "${oldPath}" : '@loader_path/'`
   if [[ "$isSystem" = "0" \
     && "$isUsrLib" = "0" \
     && "$isEmbeddedPathExe" = "0" \
     && "$isEmbeddedPathLdr" = "0" ]]; then
       libName=`basename ${oldPath}`
       frameworkName="${libName}.framework"
       isFramework=` echo ${oldPath} | grep "${frameworkName}"`
       if [[ "${#isFramework}" = "0" ]]; then
       	libName=`basename ${oldPath}`
         newPath="$vtkInstallLibDir$libName"
         printStatus "        |- CorrectLibraryDependency $libName"
#        printStatus "        |- oldPath: $oldPath"
#        printStatus "        |- newPath: $newPath"
         install_name_tool -change "${oldPath}" "${newPath}" "${2}"
       else
       printStatus "No frameworks are being corrected"
#   I am leaving this commented out as there are (as of Vtk 5.2 NO vtk  
frameworks to correct.
#        CorrectLinkedFrameworkInstallName "${oldPath}" "${2}"
       fi
    fi
}

#  
-----------------------------------------------------------------------------
#  Uses install_name_tool to correct this library's dependencies
#  $1 is a linked library to update
#  
-----------------------------------------------------------------------------
function UpdateLibraryDependencies()
{
	  printStatus "     |- UpdateLibraryDependencies $1"
	  local libFile
	  local libOutFile
	  local i
	
	  libFile="${1}"
	  libOutFile="${TmpDir}/otool-library.out"
	  otool -L "${1}" > "${libOutFile}"
	  i=0
	  exec 10<"${libOutFile}"
	  while read -u 10 line
	    do
	    if [[ ${i} -gt 1 ]]; then
	        CorrectLibraryDependency "${line}" "${1}"
	        let i=i+1
	    fi
	    let i=i+1
	  done
	  exec 10<&-
}

#  
-----------------------------------------------------------------------------
#  Uses install_name_tool to correct this framework
#  $1 is a linked framework
#  $2 is the executable
#  
-----------------------------------------------------------------------------
function UpdateFrameworkInstallName()
{
     local frameworkBundle
     local frameworkName
     local frameworkRootDir
     local libName
     if [[ -e ${1} ]]; then
         #-- Copy the Framework using the current "install_name" as  
the path
         libName=`basename ${1}`
         frameworkName="${libName}.framework"
         frameworkRootDir="${1%${frameworkName}*}"
         frameworkBundle="${frameworkRootDir}${frameworkName}"
         cp -R "${frameworkBundle}" "${PackageInstallDest}/$ 
{FrameworkPath}/."

         # Update the Executables link path to this library
         oldPath="${1}"
         libName=`basename ${oldPath}`
         newPath="${InstallNameFramework}/${1#${frameworkRootDir}*}"
         install_name_tool -change ${oldPath} ${newPath} ${2}

         # Update the install_name of the library itself
         install_name_tool -id ${newPath} "${PackageInstallDest}/$ 
{FrameworkPath}/${1#${frameworkRootDir}*}"

         UpdateLibraryDependencies "${PackageInstallDest}/$ 
{FrameworkPath}/${1#${frameworkRootDir}*}"
     fi
}

#  
-----------------------------------------------------------------------------
#  Uses install_name_tool to correct this library
#  $1 is a linked library
#
#  
-----------------------------------------------------------------------------
function UpdateDylibInstallName()
{
	printStatus "  |- UpdateDylibInstallName $1"
	if [[ -e ${1} ]]; then
	    # Update the Executables link path to this library
	    oldPath="${1}"
	    libName=`basename ${oldPath}`
	    newPath="$vtkInstallLibDir"
	    # echo "  |-  $oldPath    $vtkInstallLibDir/$libName   "

	    # Update the install_name of the library itself
	    # echo "install_name_tool -id $vtkInstallLibDir/$libName $oldPath"
	    install_name_tool -id "$vtkInstallLibDir$libName" "$oldPath"
	
	    UpdateLibraryDependencies "$oldPath"
	fi
}


#  
-----------------------------------------------------------------------------
#  Script really starts here
#  
-----------------------------------------------------------------------------

#-- Get a list of all the libraries and look over them
cd $vtkInstallLibDir
VTK_LIBS=`ls libvtk*.dylib`
for vtklib in $VTK_LIBS; do
   echo  
"-------------------------------------------------------------------------"
   echo "vtklib: $vtkInstallLibDir$vtklib"
   UpdateDylibInstallName "$vtkInstallLibDir$vtklib"

done

# -- This is just some extra code..
#
# tmpFile="${TmpDir}/otool.out"
# otool -L "${BuildBinDir}/${ApplicationExe}" > "${tmpFile}"
# i=0
# totalUpdates=`cat  "${tmpFile}" | wc -l`
# let totalUpdates=totalUpdates+0
# exec 9<"${tmpFile}"
# while read -u 9 line
#   do
#   if [[ ${i} -gt 0 ]]; then
#     UpdateExecutableDependencies "${line}" "${PackageInstallDest}/$ 
{ApplicationExe}" "${i}" "${totalUpdates}"
#   fi
#   let i=i+1
# done
# exec 9<&-


Best regards,

Elvis


Technote Qt-4.5.x-002: How to build Qt-4.5.x and vtk-5.3.x for Mac OS  
X 10.5.5 with 32-bit Carbon support

Procedure

Qt-4.5.x

Step 01: Download the latest version of Qt-4.5.x via rsync

The following command will list all the rsync modules available from  
the TrollTech server

rsync rsync://rsync.trolltech.com/

For example, to get Qt for all platform snapshots with rsync, choose a  
directory in which to install the distribution (your-qt-repository),  
and run the command:

rsync -avz rsync://rsync.trolltech.com/qt-all-4.5 <your-qt-repository>


Step 02: Patch vtk sources

Patch the QVTKWidget plugin sources by running the following command  
from the VTK/GUISupport/Qt/ folder

patch < qvtkcocoasupport.patch

Step 03: Configure and build Qt-4.5.x

In order to configure Qt-4.5.x for Mac OS X 10.5.5 with carbon support  
type the following command

./configure -platform macx-g++ -opengl -arch i386 -qt-gif -prefix / 
Developer/Applications/Qt-4.5.0

Type the following command to build Qt-4.5.x

make -j 2

Step 04: Update environment variables

Update your ~/.profile file with the following environment variables

# environment variables for vtk-5.x
export VTK_DIR=/Users/elvis/Tool/vtk-5.x/install/carbon-shared/lib/ 
vtk-5.3
export VTK_LIB_DIR=/Users/elvis/Tool/vtk-5.x/install/carbon-shared/lib/ 
vtk-5.3
export VTK_DATA_ROOT=/Users/elvis/Tool/vtk-5.x/data/

# environment variables for qt-4.4.3
export QTROOT=/Developer/Applications/Qt-4.5.0
export QT_PLUGIN_PATH=/Developer/Applications/Qt-4.5.0/plugins/designer

# the path is initially set to "/usr/bin:/bin:/usr/sbin:/sbin:/usr/ 
local/bin:/usr/X11/bin"
export PATH=$PATH:$QTROOT/bin

# environment variables for Tcl Tk
export TCL_LIBRARY=/usr/local/lib/libtcl8.5.dylib
export TK_LIBRARY=/usr/local/lib/libtk8.5.dylib
export TCLLIBPATH="$TCLLIBPATH \"/Users/elvis/Tool/vtk-5.x/install/ 
carbon-shared/lib/vtk-5.3\" \"/Users/elvis/Tool/vtk-5.x/install/carbon- 
shared/lib/vtk-5.3/Tcl\""

# the path is initially set to "/usr/bin:/bin:/usr/sbin:/sbin:/usr/ 
local/bin:/usr/X11/bin"
export PATH=$PATH:$QTROOT/bin
export DYLD_LIBRARY_PATH=$VTK_LIB_DIR:$VTKDESIGNER_LIB_DIR: 
$GCF_LIB_DIR:$GRASS_LIB_DIR:$DYLD_LIBRARY_PATH

Step 05: Install qt-4

Once everything is built, type the following command to install Qt-4.5.0

sudo make install

Qt will be installed into /Developer/Applications/Qt-4.5.0



vtk-5.3.x

Step 01: Check out vtk-5.x sources from svn

cvs -d :pserver:anonymous at public.kitware.com:/cvsroot/VTK login
(respond with password vtk)

Follow this command by checking out the source code:

cvs -d :pserver:anonymous at public.kitware.com:/cvsroot/VTK checkout VTK

This CVS tree is VTK 5.x. Execute the CVS checkout in a clean  
directory. It will create a VTK directory, overwriting any existing  
VTK tree. You will also need CMake which is the cross platform build  
system that drives VTK builds.

Issue the following command to update the source code:

cvs -d :pserver:anonymous at public.kitware.com:/cvsroot/VTK update -d VTK

For testing purposes you might wish to checkout the CVS VTKData:

cvs -d :pserver:anonymous at public.kitware.com:/cvsroot/VTKData login
(respond with password vtk)

cvs -d :pserver:anonymous at public.kitware.com:/cvsroot/VTKData checkout  
VTKData


Step 02: Configure and build vtk-5.x

Create the following directory structure

vtk-5.x/
	build/
		VTKBuild
	data/
		Data
	src/
		VTK

Type the following command to configure vtk

cd vtk-5.x/build/VTKBuild
ccmake ../../src/VTK

Select the following option

CMAKE_INSTALL_PREFIX=/Users/elvis/Tool/vtk-5.x/install/carbon-shared

VTK_USE_GUISUPPORT=ON
VTK_USE_QVTK=ON
DESIRED_QT_VERSION=4
VTK_USE_QVTK_QTOPENGL=ON


Step 03: Configure and build vtk-5.x

Type the following command to build vtk

make -j 2


Step 04: Install vtk-5.x

Type the following command to install vtk into /usr/local

sudo make install

This will install vtk files into the following directories

/usr/local/bin
/usr/local/include/vtk-5.3
/usr/local/lib/vtk-5.3

Step 05: Mike’s script to fix install_name for all the VTK libraries

ccmake ../../src/VTK
make -j 2
make install
/Users/elvis/Project/C4I/Source/script/FixVTKInstallName.sh /Users/ 
elvis/Tool/vtk-5.x/install/carbon-shared


Step 06: Install QVTKPlugin into QT Designer

If you do a "make install" of VTK, there will be a {VTK_INSTALL_DIR}/ 
plugins/designer directory with the plugin.  You can add  
{VTK_INSTALL_DIR} to your designer plugin path in the desinger
preferences dialog.

Put a copy of the dll/so in your QTDIR/plugins/designer directory.  
Also, make sure the VTK dll/so libraries can be found as well, or the  
designer will quietly ignore the plugin.


Related Topics

None.


Related Links

None.


Download

01.  FixVTKInstallName

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090903/07d204e8/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FixVTKInstallName.png
Type: image/png
Size: 4581 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090903/07d204e8/attachment.png>


More information about the vtkusers mailing list