Thread: dynamic libraries

  1. #1
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342

    dynamic libraries

    Suppose, i create a new shared library. I use it a couple of times. And then,modify it, re-compile it. When i try to use the same library file, how can i force the compiler to off-load the one that's already present in the memory and load the new one to carry on my execution?

    I came across a method where we used _init and _fini , but this will work if I am manually load or unload using dlopen() or dlclose() inside my C code only, right?
    But, if I havent done so, is there a way to solve my problem?
    In the middle of difficulty, lies opportunity

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    ... force the compiler to off-load the one in memory and load the new one ...

    No, can't be done. Just restart the process using the library. By the way, this is really a Linux programming or even tech question.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    >Just restart the process using the library
    eh? but, as i have noticed, it will still use the old library in the memory. Doesn't it?
    >By the way, this is really a Linux programming or even tech question.
    yeah, sorry about that.
    In the middle of difficulty, lies opportunity

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by kris.c
    >Just restart the process using the library
    eh? but, as i have noticed, it will still use the old library in the memory. Doesn't it?
    Not that I know of. While you're in development, the should be only one process using the library (or perhaps two if it's a client-server app where both use it), and when you stop this process, the DLL, even if it was loaded earlier, would be unloaded. Also, there are various technical reasons why I consider it pretty much impossible that the system would use a library in memory over an updated one on disk.

    Do you have a specific test case where you observed this behaviour?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Can you guide me towards any worthy online resource for shared libraries? I have just been reading a few articles here and there..
    >Do you have a specific test case where you observed this behaviour?
    I had tried a simple example where that had happened.. i will check up again.
    In the middle of difficulty, lies opportunity

  6. #6
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    >and when you stop this process, the DLL, even if it was loaded earlier, would be unloaded.

    It happened to strike me, the whole advantage of using a shared library comes down to the fact that the library in the memory can be re-used many times as its already in the memory. So, this off-sets the time consumed during the first compliation/execution. So, it will not be unloaded unless it is forced to happen, like a system shut down. (Atleast this is what i have understood)

    This again brings me back to the question I had asked first.
    In the middle of difficulty, lies opportunity

  7. #7
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    I found this : http://www.informit.com/guides/conte...eqNum=152&rl=1
    Automatic Updates

    Whenever a new version of a dynamically-linked library is installed, it automatically supercedes the previous version. When you run a program, it automatically picks the most up-to-date version without forcing the user to re-link.

    So, is this how its updated? By looking at the time values against the library file?
    In the middle of difficulty, lies opportunity

  8. #8
    .
    Join Date
    Nov 2003
    Posts
    307
    Usually because the .so (or .sl) filename is a link that points to the newest version of the library.
    For example libc.so is frequently a symbolic link.

    eg
    Code:
    lrwxrwxrwx  1 root root      13 Jan 13  2006 libc.so.6 -> libc-2.3.5.so

  9. #9
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    I happened to get one more doubt,
    While creating static libraries, we use "ranlib" to take care of the indexing part to speed up function look up when the libraries are being used. I havent come across any such function for dynamic libraries. Why is that?
    In the middle of difficulty, lies opportunity

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Because static and dynamic libraries have completely different formats. Static libraries are effectively archives (thus the .a ending) of all object files, with some additional metainformation. Dynamic libraries are full-blown ELF binaries. Any indexing is done by the linker.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  2. Identify dynamic IP address of network device
    By BobS0327 in forum Tech Board
    Replies: 2
    Last Post: 02-21-2006, 01:49 PM
  3. Dynamic Libraries and definition files
    By IconTree in forum Linux Programming
    Replies: 1
    Last Post: 08-10-2005, 01:51 PM
  4. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM
  5. Dynamic libraries
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 04-25-2002, 01:09 PM