Take the 2-minute tour ×

Possible Duplicate:
How to use dylib in Mac OS X (C++)

I have the following files:

  • lost.h
  • lost.dylib

I am struggling with the concept of how my C program knows where my lost.dylib file lives? At the top of my file I do an include #include "lost.h" but how does my program know about my lost.dylib?

share|improve this question

marked as duplicate by trojanfoe, Oli Charlesworth, Jens Gustedt, Coderama, ChrisF Nov 15 '11 at 16:06


add comment

2 Answers

up vote 2 down vote accepted

At link time it uses a combination of standard directories and user specified directories

Linker options has more information. Basically using -L option you can specify more directories to search for dylib that you are interested in.

If you are using Xcode, this link has more details

As far as runtime finding of the dynamic library is concerned. OS X does it a little bit different that other platforms. OS X embeds an "install name" inside each dynamic library. You can use otool -L to find the details

share|improve this answer
add comment

When linking, you should specify with the linker options (-L for directories, -l for libs). Your library should be named liblost.dylib, and the linker option should be -llost. (strip the 'lib' preffix and the .dylib extension).

Also, when the binary is compiled, you can use the otool command if you want to find out where your executable is searching for the dylib.

And if you want to change that directory, you can use install_name_tool.

share|improve this answer
add comment
