How to force using local shared libraries over system libraries?

前端 未结 2 572
予麋鹿
予麋鹿 2020-12-29 09:25

How can I force using a local library over the system library in linux?

I linked my executable explicitly to some .so files in my project/lib directory e.g. (../lib

2条回答
  •  一向
    一向 (楼主)
    2020-12-29 09:58

    When you link, specify the directory of the library and also use an rpath:

    -Wl,-rpath,/absolute/path/to/your/library -L/absolute/path/to/your/library -llibrary

    -L tells the linker where to find your library at link time, and -rpath tells it where to search for the library at runtime.

    Note that -L and -rpath need the directory that contains your .so file, not the actual path of the library file itself.

提交回复
热议问题