title: Autoconf and Libtool Are Insanely Stubborn about Static Linkage
body: <p>I'm using MinGW-w64 with POSIX threads. I want to build GNU gettext with POSIX threads and as shared libraries (DLLs in this case). However, when one builds runtime artifacts (such as DLLs or executables) which depend on POSIX threads with MinGW/MinGW-w64, one ends up with these artifacts being dependent on <code>libwinpthread-1.dll</code>. In my case, I want to avoid that and link any runtime artifacts against POSIX threads statically! The only way one can do that on MinGW/MinGW-w64 is to supply <code>-static</code> flag during the linkage stage. I've done that hundreds of times before, so I know that it works.</p>
  
  <p>The problem now is that I have to deal with notorious Autotools which have just proven yet again that they are absolutely inflexible, unfriendly, and cumbersome to use. So there we go:</p>
  
  <pre><code>LDFLAGS="-static-libgcc -static-libstdc++ -static" ../configure --build=x86_64-w64-mingw32 --disable-static --enable-shared --disable-java --disable-native-java --enable-relocatable --enable-threads=posix --prefix=&lt;prefix&gt;
  </code></pre>
  
  <p>Guess what? This guy somehow parses that I've added <code>-static</code> and it does the following to my build:</p>
  
  <ol>
  <li>All the GNU gettext libraries that should have been built as DLLs (due to <code>--enable-shared</code> and <code>--disable-static</code>) are now built as static libraries/archives;</li>
  <li><p>All the GNU gettext executables are built with <code>-static</code> excluded what makes them dependent on <code>libwinpthread-1.dll</code>, for instance:</p>
  
  <pre><code>gcc -pipe -Wall -Wextra -O3 -static-libgcc -static-libstdc++ -o test-lock.exe test-lock.o lock.o threadlib.o -lpthread
  </code></pre>
  
  <p>as we can see Autotools have intentionally filtered out only the <code>-static</code> without my permission and any logical reason to do so.</p></li>
  </ol>
  
  <p>I tried various things, and even found:</p>
  
  <pre><code>link_static_flag="-static"
  </code></pre>
  
  <p>in the <code>libtool</code> file. I've tried to change it to:</p>
  
  <pre><code>link_static_flag=""
  </code></pre>
  
  <p>in hope that it will prevent <code>libtool</code> from reacting like that when the <code>-static</code> flag is present. Unfortunately, no success yet. This is incredibly frustrating.</p>
  
  <p>OK, Autotools gurus, now it's finally your time to shine.</p>