Mixed static and dynamic link on Mac OS

前端 未结 2 1714
轮回少年
轮回少年 2020-12-10 21:25

I want to use gcc to produce a shared library, but i want to link some other libraries it depends on statically. Now to produce the \"standard\" dynamically linked output fi

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 21:39

    Quoting QA1393,

    Normally, the linker goes through each path in the search paths one at a time to find a dynamic version of the library. If none is found, it goes through each of those paths looking for a static version of the same library. There is no way to choose a static library over a corresponding dylib if both libraries are in the same directory without using the -l linker option and absolute paths to each library.

    As recommended by QA1393, you can place your static libraries in a different directory, use -L/path/to/static/libraries before other occurrences of -L that could point to dynamic libraries, and -search_paths_first so that the linker tries both .dylib (which won’t be there) and .a in the first search path before searching the next search path and so forth.

提交回复
热议问题