If I compile my source code with “-L.” the dynamic library libmd5.so can be found.
gcc main.c -g -O2 -Wall -o main -L. -lmd5 -lcr
But if I leave the “-L.”-option away, the linker does not find the dynamic library. How can I change that without having to invoke “-L.”?
(additional info libmd5.so and libmd5.so.1.0.1 are located in /home/user/ba)
There’s really nothing wrong with the -L flag, so you shouldn’t try so hard to get rid of it – is it at runtime you have problems, as the system won’t load the libraries you link to ? Here’s some options :
export LD_LIBRARY_PATH=/home/user/baandexport LIBRARY_PATH=/home/user/ba.This will have effect only for the current shell.-L .here though). Add-L /home/user/ba -Wl,-rpath,/home/user/bato your linker flags. This will have effect only for the executable you’re making./usr/lib. This will be system wide.The above have effect at runtime as well – it’ll try to find libmd5.so in /home/user/ba or other library search paths for the system when you run the app as well.