Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic library & Dynamic library - more C++ fun
    primarykey
    data
    text
    <p>Let's say I want to create a dynamic library <code>dynamic.so</code>, but my code references a function that exists in some other, static library <code>static.a</code>. Naturally, if I compile and link with <code>g++</code> and the <code>-shared</code>option, <code>dynamic.so</code> will expect the referenced function to be implemented in some other dynamic library that I would have to link at runtime together with <code>dynamic.so</code>. In other words, it will be happy as long as I do <code>-l static</code> (modulo syntax).</p> <p>But since that other library is actually a static one, I cannot do that. Let's assume I can not link the static library at compile time of my main program either, but I'm forced to only use dynamic libraries. So what I really want is to include the compiled code off the referenced function from <code>static.a</code> in <code>dynamic.so</code>.</p> <p><a href="https://stackoverflow.com/a/2649792/261142">This answer</a> to a related question suggests using the <code>--whole-archive</code> option to include <code>static.a</code> in <code>dynamic.so</code>. However, in my case, <code>static.a</code> is huge. And I really don't need all of it, I only need that one function definition.</p> <p><a href="https://stackoverflow.com/a/2246926/261142">This answer</a> to another question explains that linking to a static library at compile time means that only the code that is actually referenced gets included in the binary. Well, this is exactly what I would like to do for my single function reference! I don't really want the whole static archive in there.</p> <p>But how can I achieve that? How can I include just the required parts of <code>static.a</code> in <code>dynamic.so</code>? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload