title: Force linking a static library into a shared one with Libtool
body: <p>I have a library (<em>libfoo</em>) that is compiled <strong>using libtool</strong> into two objects: libfoo.a and libfoo.so.</p>
  
  <p>I have to create, <strong>using libtool</strong> also, another library (<em>libbar</em>) that will be a single shared library (libbar.so) containing all libfoo's code.</p>
  
  <p>In order to do this, I have to force <em>libbar</em> to link against <strong>libfoo.a</strong>, and not libfoo.so.</p>
  
  <p>I am in an <strong>autotools</strong> environment, so I have to solve this using standard <em>configure.in</em> or <em>Makefile.am</em> rules.</p>
  
  <p>I tried several things, like in configure.in :</p>
  
  <pre><code>LDFLAGS="$LDFLAGS "-Wl,-Bstatic -lfoo -Wl,-Bdynamic"
  </code></pre>
  
  <p>That always results in the -Wl flags on the linking line; but -lfoo has disappeared and has been placed in an absolute-path form (<em>/opt/foo/lib/libfoo.so</em>) at the beginning of it. </p>
  
  <p>I also tried:</p>
  
  <pre><code>LDFLAGS="$LDFLAGS "-L/opt/foo/lib libfoo.a"
  </code></pre>
  
  <p>or in Makefile.am:</p>
  
  <pre><code>libbar_la_LDADD = -Wl,-Bstatic -lfoo -Wl,-Bdynamic
  </code></pre>
  
  <p>and</p>
  
  <pre><code>libbar_la_LTLIBRARIES = libfoo.a
  </code></pre>
  
  <p>etc etc (with many, many variants !)</p>
  
  <p>But I think that definitely I do not have knowledge enough of Autotools/Libtool to solve this alone. I have not been able to find information on the Net about it, always slightly different issues.</p>