title: How do I fix undefined reference to _imp__*?
body: <p>I'm trying to compile something that depends on gtkspell, which
  depends on enchant, under MinGW.  I'm getting errors like
    <code>gtkspell/gtkspell.c:757: undefined reference to '_imp__enchant_broker_init'</code>
  I suspect this is either due to the fact that I'm trying to link
  againt a {static,dynamic} library when I should be linking against the
  other one, or because there's only one underscore before the imp and
  there should be two;  I get</p>
  
  <pre><code>$ objdump -t /d/opt/enchant-1.6.0/lib/libenchant.a | grep enchant_broker_init
  [ 85](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00002ac0 _enchant_broker_init
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$ objdump -t /d/opt/enchant-1.6.0/lib/libenchant.dll.a | grep enchant_broker_init
  [  6](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _enchant_broker_init
  [  7](sec  3)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __imp__enchant_broker_init
  </code></pre>
  
  <p>The internet
  (http://lists.freedesktop.org/archives/gstreamer-devel/2007-January/013975.html)
  suggests that the imp mangling comes from</p>
  
  <pre><code>_declspec(dll{import,export})
  </code></pre>
  
  <p>though enchant seems to use</p>
  
  <pre><code>__declspec(dll{import,export})
  </code></pre>
  
  <p>, and commenting out the relevant lines in enchant.h makes gtkspell.c
  request <code>enchant_broker_init</code> rather than <code>_imp__enchant_broker_init</code>, but
  doesn't change the symbols that show up in libenchant.  Is there a way
  to make gcc not mangle the names, or does anyone have ideas about what
  might be going wrong/how to fix it?</p>
  
  <p>Here's a minimal example that reproduces the problem on my system:</p>
  
  <p>If I have a file enchanttest1.c with contents</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;enchant.h&gt;
  
  int main()
  {
  #ifdef ENCHANT_MODULE_EXPORT
      printf("\nEnchant found\n");
  #else
      printf("\nEnchant not found\n");
  #endif
      return 0;
  }
  </code></pre>
  
  <p>and a file enchanttest2.c with contents</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;enchant.h&gt;
  
  int main()
  {
      EnchantBroker *b = enchant_broker_init();
  #ifdef ENCHANT_MODULE_EXPORT
      printf("\nEnchant found\n");
  #else
      printf("\nEnchant not found\n");
  #endif
      return 0;
  }
  </code></pre>
  
  <p>then</p>
  
  <pre><code>gcc enchanttest1.c `pkg-config --cflags enchant` &amp;&amp; ./a.exe
  </code></pre>
  
  <p>gives <code>Enchant found</code> but</p>
  
  <pre><code>gcc enchanttest2.c `pkg-config --cflags enchant` &amp;&amp; ./a.exe
  </code></pre>
  
  <p>gives</p>
  
  <pre><code>C:\Users\JASONG~1\AppData\Local\Temp\ccyDLptc.o:testenchant.c:(.text+0xf): undefined reference to `_imp__enchant_broker_init'
  collect2: ld returned 1 exit status
  </code></pre>