2

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?

Community
  • 1
  • 1
Coderama
  • 11,050
  • 12
  • 44
  • 58

2 Answers2

2

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

parapura rajkumar
  • 24,045
  • 1
  • 55
  • 85
1

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.

Santiago V.
  • 1,088
  • 8
  • 24