• 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
Re: Proper way to link dynamic libraries?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper way to link dynamic libraries?


  • Subject: Re: Proper way to link dynamic libraries?
  • From: Dave Carrigan <email@hidden>
  • Date: Mon, 4 Aug 2008 17:04:38 -0700


On Aug 4, 2008, at 3:52 PM, Brian Jones wrote:

I was wondering if there was a correct way to link dynamic libraries in C++ projects? I'm pretty new to xcode and mac compared to visual studio and windows. I made a program to test out boost::thread. At first I was getting linking errors, but then including a copy of the dylib in the directory that contains the executable solved that problem - the app runs fine . But then when I try to manually execute the app, I get a error "image not found." I've heard/read things about DYLD_LIBRARY_PATH and stuff, but it just does not make sense to me. At least how use it in the xcode IDE.

Linking to dynamic libraries is very similar to linking to DLLs in windows. When it comes time to load the app, the OS has to resolve the location of all the dylibs or DLLs before it can load. If it can't find them, then it will complain and not run the app.


The big difference between Mac OS and Windows is the search algorithm that it uses. Windows searches in this order

1. The directory where the executable is (Mac OS does not).
2. The current directory (Mac OS does not).
3. The Windows system directories (Mac OS searches its equivalents, such as /usr/lib).
4. The directories listed in the PATH environment variable (MacOS uses the directories listed in DYLD_LIBRARY_PATH environment variable).


To debug DLL dependencies in Windows, you use Depends.exe. The Mac OS analog is otool. It's a command-line tool that you run with

  otool -L the-binary

One thing that you can do with Mach-O binaries that you can't with Windows is to store more detailed path information for the dylibs inside the binary. This is often done to package an app for distribution, usually as the last stage of the build, and involves the install_name_tool command.

If you just want to run your binary outside of Xcode, your easiest approach is to set DYLD_LIBRARY_PATH. Open up a terminal and do:

  export DYLD_LIBRARY_PATH=/the/directory/where/the/dylib/is
  open /the/path/to/MyApp.app

Basically is there a way to link dynamic libraries without having to learn the unix os?


If you're planning to develop for Mac OS, you should learn the unix os, just as you should know the Windows command line if you want to develop for Windows. Any developer who avoids this is intentionally crippling their ability to get their work done.

--
Dave Carrigan
email@hidden
Seattle, WA, USA

Attachment: PGP.sig
Description: This is a digitally signed message part

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

This email sent to email@hidden

References: 
 >Proper way to link dynamic libraries? (From: Brian Jones <email@hidden>)

  • Prev by Date: Re: Xcode 3.1 alert
  • Next by Date: User Header Search Path trouble
  • Previous by thread: Proper way to link dynamic libraries?
  • Next by thread: User Header Search Path trouble
  • Index(es):
    • Date
    • Thread