• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Link to Dylibs Depending on Other Dylibs [Solution for Matlab]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Link to Dylibs Depending on Other Dylibs [Solution for Matlab]


  • Subject: Link to Dylibs Depending on Other Dylibs [Solution for Matlab]
  • From: Ben Dubin-Thaler <email@hidden>
  • Date: Sun, 28 Aug 2005 20:32:58 -0400

Hi,

Here is the solution to a problem that I had recently that I know some other people have had, so I wanted to post it.

Here's the problem:
Matlab wants you to use a shell script they provide (named mex) to compile c sources that make function calls to libmat.dylib (the functions allow one, amongst other things, to open data daved in the proprietary .mat data format). When one tries forgo their script and compile matlab functions in an xcode project, even if you tell xcode about all the dependencies, the linker complains that it cannot find them in some strange relative path locations that you never told it about.


Here's the solution:
Turns out that the install names in the libraries that tell the library where to find itself and also where the libraries it depends on are only work if you are using the aforementioned Matlab mex script to do your compiling and linking. I fixed this problem by writing a perl script that uses the unix commands otool and install_name_tool to locate and change the dependency lines for each library.


In summary, if you are trying to link matlab libraries in your xcode project and are getting error messages that look like this:

/usr/bin/ld: warning can't open dynamic library: libustdio.24.dylib
(checking for undefined symbols may be affected) (No such file or
directory, errno = 2)

And if, at runtime, like this:

dyld: Library not loaded: ../../bin/mac/libeng.dylib
  Referenced from: /Applications/MATLAB704/bin/mac/libmat.dylib
  Reason: image not found

Then you need to change the install names in the matlab dylibs so that they aren't assuming your linker is running from the directory that the the mex script is installed at. I've included a perl script that will help you do this.

I posted this solution to the mathworks list here: http:// newsreader.mathworks.com/WebX?email@hiddenChZ5hn.0@.ef0c223
but I wanted to post it here too because some people on this list have described having similar issues (see http://www.cocoabuilder.com/ archive/message/cocoa/2003/12/3/871).


If Mathworks would make a framework out of the matlab libraries all of these troubles would go away, but they are only barely supporting OSX as it is - right now Matlab runs through X11 on OSX with no native Cocoa support.

Best,
Ben


The script for changing the dependencies follows. Also, see the notes after the script.


#! /usr/bin/perl
use File::Basename;

# specify the top library in the command line argument
$toplibfull = $ARGV[0];

$topdir = dirname $toplibfull;
$toplib = basename $toplibfull;

chdir $topdir or die "cannot change dir to $topdir\n";

#chomp(@olib = `otool -L $toplib`);

#### go through and process the names that are ../../something.dylib
foreach (`otool -L $toplib`) {
    if(/\/([a-zA-Z0-9\.]+\.dylib[0-9\.]*)\s/) {
        print "Dep lib = $1\n";
        push(@deplibs, $1)
    }
}


#### change lib id name if($toplib eq $deplibs[0]) { $idname = "\@"."executable_path/../Frameworks"."/". shift @deplibs; print "idchange to $idname\n"; system "install_name_tool", "-id", $idname, $toplib; }

#### process dependent library paths
foreach (@deplibs) {
$olddepname = "../../bin/mac/".$_;
$depname = "\@"."executable_path/../Frameworks"."/". $_;
print "change $olddepname to $depname\n";
system "install_name_tool", "-change", $olddepname, $depname, $toplib;
}


Note1: Since I am interested in bundling the matlab dylibs with my application, I am actually copying them into the frameworks directory of my project, so I want them to referenced by @executable_path/../ Frameworks/your.dylib, but you could just as easily set the dependencies to the libraries directory where they are installed by matlab, which for MATLAB704 is /Applications/MATLAB704/bin/mac/ your.dylib.

Note 2: This perl script could be really fancy and recursively correct the install names for all the libraries that the starting library you give as an argument depends on. Right now you have to run the tool once for every library you know is in your dependency list.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: NSCell -setFont Clobbers Editability?
  • Next by Date: Re: Different System Fonts in Tiger, Panther, etc.
  • Previous by thread: Re: Different System Fonts in Tiger, Panther, etc.
  • Next by thread: Scaled printing on Panther
  • Index(es):
    • Date
    • Thread