To build a shared library called libs.so consisting
of one translation unit s.cc:
$ g++ -fPIC -shared -o libs.so s.cc
To build a program main.cc and link it with libs.so
$ g++ main.cc libs.so -o main
For the resulting executable main to run successfully, it needs
to find your libs.so and for this to happen, you need to:
1) place it in some directory (say, /home/zhupanov/lib). You must place the actual libs.so file there, not a soft link to it.
2) Create a new .conf file for ldconfig (the name does not matter,
as ldconfig processes all config files in /etc/ld.so.conf.d/)
$ sudo emacs /etc/ld.so.conf.d/zhupanov.conf
The file should contain 1 line, with the name of that directory
/home/zhupanov/lib
3) Rerun ldconfig, verifying libs.so appears in the list of libs
$ sudo ldconfig -v | grep libs.so
Naturally, the last steps require root access. I understand
that one can bypass it by manipulating LD_LIBRARY_PATH, but I have
failed to do so successfully.
of one translation unit s.cc:
$ g++ -fPIC -shared -o libs.so s.cc
To build a program main.cc and link it with libs.so
$ g++ main.cc libs.so -o main
For the resulting executable main to run successfully, it needs
to find your libs.so and for this to happen, you need to:
1) place it in some directory (say, /home/zhupanov/lib). You must place the actual libs.so file there, not a soft link to it.
2) Create a new .conf file for ldconfig (the name does not matter,
as ldconfig processes all config files in /etc/ld.so.conf.d/)
$ sudo emacs /etc/ld.so.conf.d/zhupanov.conf
The file should contain 1 line, with the name of that directory
/home/zhupanov/lib
3) Rerun ldconfig, verifying libs.so appears in the list of libs
$ sudo ldconfig -v | grep libs.so
Naturally, the last steps require root access. I understand
that one can bypass it by manipulating LD_LIBRARY_PATH, but I have
failed to do so successfully.

