[Insight-users] Using compiled ITK libraries

Michael Jackson mike.jackson at bluequartz.net
Thu Apr 2 15:19:22 EDT 2009


Welcome to the world of dynamic libraries. The error is saying that  
the executable can not find the libITKAlgorithms.3.4.dylib dynamic  
library. Which on a vanilla OS X box will be the case. There are a few  
solutions. The quick fix is to 'export DYLD_LIBRARY_PATH=/Users/Shared/ 
itkTest/Build/Release' on a terminal then run your program. Probably  
works now. The issue is that OS X (and linux) use a technique called  
the "install_name" (OS X) or rpath(linux) which actually embeds the  
path to the library in the library. When the program is linked to the  
library the executable takes note of those paths. When the executable  
is launched it uses those notes to find the library without having to  
use DYLD_LIBRARY_PATH. The problem is that ITK builds its libraries  
without any "install_name" in the library. You can fix this by using  
the "install_name_tool" to set the paths correctly. In practice this  
isn't done because it is _very_ difficult and is _very_ error prone  
because you have to get all the dependencies correct for each library  
that itk depends on which becomes recursive.

   The _much_ easier way is to just build ITK as Static libraries.  
This removes all the issues above and your program will "just work".

Hope That helps.

PS: You _really_ don't want to try and hand build itk without CMake.  
The CMake files are there for a reason. Use them. You are just coming  
up the learning ladder that everyone else has to. Kinda like a "right  
of passage".

_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio



On Apr 2, 2009, at 3:08 PM, bnsteel wrote:

>
> Thanks Mike,
>
> My success has spawned a new question
>
> When I followed your example, I don't get any errors when building,  
> but when I run the helloWorld example, I get the error,
>
>      dyld: Library not loaded: libITKAlgorithms.3.4.dylib
>         Referenced from: /Users/Shared/itkTest/Build/Release/itkTest
>         Reason: image not found
>
>
> I ran this using Xcode and from the command line.  In both cases, I  
> get the same results: compiles fine, can't link to the libs.
>
> I'm in the process of experimenting with building VXL and ITK by  
> hand to see if I can find a combination that will link with my  
> helloWorld code.  I wouldn't have thought it would be this hard,  
> since there is a XCode option in ccmake.
>
> (here's the helloworld code, just so you know how bland it is):
>
> #include <iostream>
> #include "itkImage.h"
>
> int main (int argc, char * const argv[]) {
>    typedef itk::Image< unsigned short, 3 > ImageType;
> 	ImageType::Pointer image = ImageType::New();
> 	std::cout << "ITK Hello World !" << std::endl;
> 	return 0;
> }
>
>
> Any insight would be welcomed.
>
>
> -- 
> View this message in context: http://n2.nabble.com/Using-compiled-ITK-libraries-tp2575253p2577033.html
> Sent from the ITK Insight Users mailing list archive at Nabble.com.
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list