I am trying to modify this shared library (with .so) extension on Linux. I am inserting some printf statement and fprintf statement to debug, and it has no effect. I removed the .so file and realized that the the program still runs fine. Does it mean that the program is loaded into memory?? (But I'm sure only the program I'm testing for uses that .so file though)
How do I get it to unload so I can make sure my program is loading the modified one?
Shared libraries are the most common way to manage dependencies on Linux systems. These shared resources are loaded into memory before the application starts, and when several processes require the same library, it will be loaded only once on the system. This feature saves on memory usage by the application.
Simply put, A shared library/ Dynamic Library is a library that is loaded dynamically at runtime for each application that requires it. Dynamic Linking doesn't require the code to be copied, it is done by just placing name of the library in the binary file.
To create a shared library in C++ using G++, compile the C++ library code using GCC/ G++ to object file and convert the object file to shared (. SO) file using gcc/ g++. The code can be used during the compilation of code and running executable by linking the . SO file using G++.
Once you've created a shared library, you'll want to install it. The simple approach is simply to copy the library into one of the standard directories (e.g., /usr/lib) and run ldconfig(8). Finally, when you compile your programs, you'll need to tell the linker about any static and shared libraries that you're using.
No, shared libraries are not cached in memory. If you have deleted the .so
file and your program still runs, then either:
.so
of the same name from a different location, or.so
If the .so
is supposed to be loaded at program startup, then you can use ldd
to find out where your OS thinks the .so
actually is.
If the .so
is loaded dynamically at runtime, then perhaps strace
will be able to help pinpoint what is happening.
You can read /proc/1234/maps
to find out the memory map of process 1234. This also shows the dynamically loaded shared objects.
You may use the LD_LIBRARY_PATH
environment variable to change the path of shared libraries and ldconfig
to upgrade its cache. Look also in /etc/ld.so.conf
etc.
Of course, you have to restart the program loading your shared library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With