[lug] Need help understanding linking and loading shared libraries

Hugh Brown hugh at math.byu.edu
Mon Feb 4 18:28:19 MST 2008


Michael Hirsch wrote:
> I thought I mostly understood this, but I'm definitely missing something.
> 
> I have a library, lets call it libboost.so.1.33.1, though the real
> name is longer.  There is also a copy of this file named libboost.so
> 
> I build my own library, lets call it libfoo.so which relies on
> libboost.  The option to g++ is -lboost.
> 
> Finally, I have an executable, bar, that needs libfoo.so (again, with -lfoo).
> 
> All this works.  But now, if I only have libboost.so and not
> libboost.so.1.33.1 the loader will complain that it can't file
> libboost.so.1.33.1.  In fact, "ldd bar" reports libboost.so.1.33.1,
> rather than libboost.so like I expected.
> 
> I was under the impression that since libboost.so satisfies all the
> link requirements for libfoo, that it would satisfy the loader.  Is
> there something I've have done that makes libfoo.so know the exact
> version number of the libboost.so library?  Is there a way to turn off
> this exactness requirement?
> 
> I expect I'm missing some seemingly trivial but crucial information,
> but don't know what that is.
> 
> Thanks,
> 
> Michael


Usually libboost.so is a symbolic link to the versioned library.  So if 
you link in -lboost it will use the target of the symbolic link (i.e. 
libboost.so.1.33.1).

As to the real question, "how do I get my executable to expect 
libboost.so instead of libboost.so.1.33.1"  I don't have an answer.  I'd 
guess that there is an option in g++ that controls how linking is done.

Hugh



More information about the LUG mailing list