Gcc Linkage -L option: Alternative ways to specify a path to a dynamic library

If I compile my source code with "-L". can find the dynamic library libmd5.so.

gcc main.c -g -O2 -Wall -o main -L. -lmd5 -lcr

But if I leave the โ€œ-L.โ€ Option, the linker will not find the dynamic library. How can I change this without having to refer to "-L"?

(additional information libmd5.so and libmd5.so.1.0.1 are in / home / user / ba)

+3
source share
2 answers

-L , - , , ? :

  • /home/user/ba /etc/ld.so.conf( ) ldconfig . .
  • LIBRARY_PATH ( ) LD_LIBRARY_PATH ( ). export LD_LIBRARY_PATH=/home/user/ba export LIBRARY_PATH=/home/user/ba. .
  • rpath ( -L .). -L /home/user/ba -Wl,-rpath,/home/user/ba . , .
  • , /usr/lib. .

- libmd5.so /home/user/ba .

+8

LIBRARY_PATH.

export LIBRARY_PATH=/home/user/ba
+1

Source: https://habr.com/ru/post/1757406/


All Articles