Understanding Shared Libraries (Win vs. Lin)

From what I understand about shared (dynamically linked) libraries on Windows: First an executable will search its own directory for the library. If it is not found, it will look in PATH.

Now I have just learned how to create and link to shared libraries on Linux using the GNU C++ compiler, and this is what I have experienced: I have been able to link to a shared library in one of three ways. First by absolute path, the library has to be in the specified path no matter what, or the executable will fail to link to it:
g++ test.cpp mylib.h /home/user/Programming/test/libmylib.so -o test

Next, linking to the library in the executables directory. The library must be in the same directory as the executable:
g++ test.cpp mylib.h ./libmylib.so -o test

And last, linking to the library which must be placed somewhere in PATH:
g++ test.cpp mylib.h libmylib.so -o test


What I want to understand is do I have to choose between one of these methods? Or can I combine the executable dir & PATH methods and place my lib in either executable dir or PATH? I know that I can add the executables dir to PATH, but I was wondering if this could be done without adjusting environment variables.
You can set the path in LD_LIBRARY_PATH

But you'll need to read this:
Why LD_LIBRARY_PATH is bad
http://linuxmafia.com/faq/Admin/ld-lib-path.html

And probably this:
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
closed account (S6k9GNh0)
LD_LIBRARY_PATH isn't recommended. In common times, they now use a configuration file in /etc/ld.so.conf or something.

Also, shared libraries in Linux are very simple. You mainly place most shared libraries inside of /usr/local/lib or /usr/lib which helps prevent multiples of the same library. You then place a version tag at the end of it and apply a hard link to the library version your wanting named after the libraries original name.
Well, it's no big deal either way. I'm totally happy to put my libs in a shared lib directory. I guess I was just asking out of curiosity. The hard linking sounds like a very good idea.
Topic archived. No new replies allowed.