开发者

What are the default search directories to link a library on Mac OS X

I've build the Google Test with CMake on Mac OS X and get two shared libraries: libgtest.dylib and li开发者_运维问答bgtest_main.dylib. And now I need install both them. I know there are some default search directories on Linux, such as /usr/lib, /usr/local/lib, etc.. But I am unfamiliar with Mac OS X and don't know where to place those libraries.

In Mac OS X Directory Structure, I find there are three directories of libraries: ~/Library, /Library and /usr/lib. And I've tried to place gtest libraries into these directories respectively and found out only /usr/lib works.

What I want to know is wether there are some rules about the default search directories on Mac OS X just like on Linux and Windows.


Take a look at the default values for environment variables used by the dyld linker:

DYLD_FALLBACK_LIBRARY_PATH
   ...
By default, it is set to $(HOME)/lib:/usr/local/lib:/lib:/usr/lib

This article about "Deploying an Application on Mac OS X" and other article about "Mac OS X installers" may also help.


In addition to @linuxbuild's answer, I've found the article "Dynamic Library Programming Topics > The Library Search Process" from Apple's Developer archive helpful. It explains that the search order differs for libname.dylib and path/to/libname.dylib.

When the library name is a filename (not a path with directory names), the dynamic loader searches for the library in the following order:

  1. $LD_LIBRARY_PATH
  2. $DYLD_LIBRARY_PATH
  3. The process’s working directory
  4. $DYLD_FALLBACK_LIBRARY_PATH

When the library name contains at least one directory name (a relative or fully qualified pathname), the dynamic loader searches for the library in the following order:

  1. $DYLD_LIBRARY_PATH using the filename
  2. The given pathname
  3. $DYLD_FALLBACK_LIBRARY_PATH using the filename
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜