I've been programming a while but I still don't fully understand how the linker behaves.
For example, today I downloaded and installed a library that I want to use in my application in Linux. (It was Xerces – for parsing XML files).
I created a makefile and gave it the path to the .so and .a files in my command : -L/usr/local/lib and also told it the name of the library to include : -lxerces-c-3.1.
My application compiled fine but failed during runtime with "cannot open shared object file libxerces-c-3.1.so". Why would this be the case, when I properly give it the path and name in the makefile?
I then added the library path to the LD_LIBRARY_PATH variable in my .bashrc file and then it worked. That's fine , but if I now remove the path to the library in my makefile and don't even include the name of the library , it still works.
I'm confused as to what is going on here. How can it still find the correct library just by assigning the path to the LD_LIBRARY_PATH variable and will only work if I do so? I have read elsewhere to not even use LD_LIBRARY_PATH.
I appreciate any answer for this. The question is a bit long and hopefully not off-topic but I hope others can learn from it too. Thanks