title: How do I create a shared library using autotools
body: <p>I've created an autotools based package that generates a <code>libxxx.a</code> static library. What is the correct way to alter my <code>configure.ac</code> and <code>Makefile.am</code> files to create a <code>libxxx.so</code> shared library instead?</p>
  
  <p>I did try following the instructions at:</p>
  
  <p><a href="https://stackoverflow.com/questions/8916425/how-to-create-a-shared-library-so-in-an-automake-script">How to create a shared library (.so) in an automake script?</a></p>
  
  <p>I added <code>LT_INIT</code> to the end of my <code>configure.ac</code>, and replaced references to <code>libtest_a</code> with <code>libtest_la</code> in my <code>src/Makefile.am</code></p>
  
  <p>I then ran:</p>
  
  <pre><code>$ libtoolize &amp;&amp; aclocal &amp;&amp; autoconf &amp;&amp; automake --add-missing &amp;&amp; ./configure &amp;&amp; make
  </code></pre>
  
  <p>which gets me a:</p>
  
  <blockquote>
    <p>/bin/bash: --mode=compile: command not found</p>
  </blockquote>
  
  <p>error message. What appears to be happening is that the build system has forgotten to use a compiler.</p>
  
  <p>These are the original <code>configure.ac</code></p>
  
  <pre><code>AC_INIT([libtest], [1.0])
  AM_INIT_AUTOMAKE([-Wall -Werror foreign])
  CXXFLAGS="$CXXFLAGS -std=c++0x"
  AC_PROG_CXX
  AM_PROG_AR
  AC_PROG_RANLIB
  AC_CONFIG_FILES([Makefile])
  AC_OUTPUT([src/Makefile])
  </code></pre>
  
  <p>and <code>src/Makefile.am</code> files</p>
  
  <pre><code>AM_CPPFLAGS=-I../include
  lib_LIBRARIES = libtest.a
  libtest_a = -version-info 0:0:0
  libtest_a_SOURCES = \
  </code></pre>
  
  <p>And here are the updated versions</p>
  
  <pre><code>AC_INIT([libtest], [1.0])
  AM_INIT_AUTOMAKE([-Wall -Werror foreign])
  CXXFLAGS="$CXXFLAGS -std=c++0x"
  AC_PROG_CXX
  AM_PROG_AR
  AC_PROG_RANLIB
  AC_CONFIG_FILES([Makefile])
  AC_OUTPUT([src/Makefile])
  LT_INIT
  </code></pre>
  
  <p>and</p>
  
  <pre><code>AM_CPPFLAGS=-I../include
  lib_LTLIBRARIES = libtest.la
  libtest_la = -version-info 0:0:0
  libtest_la_SOURCES = \
  </code></pre>
  
  <p>respectively.</p>
  
  <p>You'll notice the added <code>LT_INIT</code> in <code>configure.ac</code> and references to <code>libtest.la</code> instead of <code>libtest.a</code>, as well as the change to <code>lib_LTLIBRARIES</code> in <code>src/Makefile.am</code></p>
  
  <p>In both cases I've left out the value assigned to <code>..._SOURCES</code> as irrelevant to this discussion (as well as rather long).</p>