<story><title>Anatomy of Linux Dynamic Libraries</title><url>https://developer.ibm.com/tutorials/l-dynamic-libraries/</url></story><parent_chain></parent_chain><comment><author>chrsig</author><text>This is a good primer on the subject.&lt;p&gt;One of the major projects I maintain at $work is an apache module, which has given me so much grief because of the fact that it gets dynamically loaded (and then unloaded, and then reloaded)&lt;p&gt;It&amp;#x27;s been very enlightening, but there&amp;#x27;s no shortage of frustration.&lt;p&gt;One major points is that a dynamically loaded library can have undefined symbols that are found (or not!) at runtime.  This can introduce a lot of trouble when trying to make a test binary.  Especially in apache&amp;#x27;s case, since any of the `ap_` symbols are only compiled into the executable, and aren&amp;#x27;t available as a static or shared library.&lt;p&gt;In that situation, the only recourse that I&amp;#x27;m aware of is to supply your own implementations of those functions that get compiled into the test binary (&lt;i&gt;not&lt;/i&gt; the dynamic library under test, since that will create a collision when it&amp;#x27;s loaded)&lt;p&gt;Another thing to consider is that linux&amp;#x2F;elf shared libraries can be either dynamically loaded or dynamically linked.  This is not true on all platforms, so it&amp;#x27;s not advisable to lean into it if portability matters.&lt;p&gt;I recommend reading the ld.so manpage[0] -- in particular it outlines many environment variables to control the runtime linker.  Notably, LD_DEBUG can be a life saver.&lt;p&gt;Lastly, I&amp;#x27;ll also warn against using any global&amp;#x2F;static memory in a dynamically loaded library.  It can be unloaded&amp;#x2F;reloaded, and that can create a lot of havoc, especially if a pointer to that memory gets saved somewhere that survives the unload, and then is accessible after the library gets reloaded.&lt;p&gt;libprotobuf is a major victim of these types of issues - which is why (or a major contributor) to why the libprotobuf-lite library exists.&lt;p&gt;[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;man7.org&amp;#x2F;linux&amp;#x2F;man-pages&amp;#x2F;man8&amp;#x2F;ld.so.8.html&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;man7.org&amp;#x2F;linux&amp;#x2F;man-pages&amp;#x2F;man8&amp;#x2F;ld.so.8.html&lt;/a&gt;</text></comment>
<story><title>Anatomy of Linux Dynamic Libraries</title><url>https://developer.ibm.com/tutorials/l-dynamic-libraries/</url></story><parent_chain></parent_chain><comment><author>ghotli</author><text>I have to care about this sort of thing at great length in my current work. Targeting hundreds of linux &amp;#x2F; embedded environments. I picked up a tip or two and in general this is a very well written overview of the moving pieces I wish I&amp;#x27;d found when I first had to dig into this domain</text></comment>