title: CodeBlocks: how can I link libstdc++ dynamically?
body: <p>Possibly I will make some implicit assumptions. If any of them are wrong, please correct me.</p>
  
  <h2>Environment</h2>
  
  <p>Win32, TDM GCC 4.6.1, Codeblocks 10.05, Codeblocks is able compile C++ using the gnu toolchain.</p>
  
  <h2>Problem</h2>
  
  <p>As far as I know it is possible to link the stdlibc++ dynamically and statically too. Currently CodeBlocks links libstdc++ <strong>statically</strong>. Although I could not find any settings relating to the dynamic/static linking in the codeblocks "build settings" panel, I could verify, using process monitor the it links the c++ standard library statically.</p>
  
  <p>CodeBlocks executes g++ with these parameters:</p>
  
  <pre><code>mingw32-g++.exe  -o bin\Release\fltk-hello.exe
  obj\Release\fltk-hello.o   -s C:\MinGW32\lib\libfltk.a
  C:\MinGW32\lib\libgdi32.a C:\MinGW32\lib\libole32.a
  C:\MinGW32\lib\libuuid.a C:\MinGW32\lib\libcomdlg32.a
  C:\MinGW32\lib\libcomctl32.a
  </code></pre>
  
  <p>Then, there is a call from g++:</p>
  
  <pre><code>"c:/mingw32/bin/../libexec/gcc/mingw32/4.6.1/collect2.exe"
  "-Bdynamic" "-o" "bin\Release\fltk-hello.exe" "-s"
  "c:/mingw32/bin/../lib/gcc/mingw32/4.6.1/../../../crt2.o"
  "c:/mingw32/bin/../lib/gcc/mingw32/4.6.1/crtbegin.o"
  "-Lc:/mingw32/bin/../lib/gcc/mingw32/4.6.1"
  "-Lc:/mingw32/bin/../lib/gcc"
  "-Lc:/mingw32/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/lib"
  "-Lc:/mingw32/bin/../lib/gcc/mingw32/4.6.1/../../.."
  "obj\Release\fltk-hello.o" "C:\MinGW32\lib\libfltk.a"
  "C:\MinGW32\lib\libgdi32.a" "C:\MinGW32\lib\libole32.a"
  "C:\MinGW32\lib\libuuid.a" "C:\MinGW32\lib\libcomdlg32.a"
  "C:\MinGW32\lib\libcomctl32.a" "-Bstatic" "-lstdc++" "-Bdynamic"
  "-lmingw32" "-lgcc" "-lmoldname" "-lmingwex" "-lmsvcrt" "-ladvapi32"
  "-lshell32" "-luser32" "-lkernel32" "-lmingw32" "-lgcc" "-lmoldname"
  "-lmingwex" "-lmsvcrt"
  "c:/mingw32/bin/../lib/gcc/mingw32/4.6.1/crtend.o"
  </code></pre>
  
  <p>Now, this part</p>
  
  <pre><code>"-Bstatic" "-lstdc++"
  </code></pre>
  
  <p>Makes it clear, that stdc++ is linked statically. I could also verify in process explorer that the loaded dlls do not contain libstdc++-6.dll. </p>
  
  <h2>What I have tried so far</h2>
  
  <p>I looked around the codeblocks build settings pages and found nothing. Codeblock provides the possibility to add parameters to g++. Unfortunately I could not find explicit gcc parametes to turn on the dynamic linking of libstdc++, the docs at <a href="http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html" rel="nofollow">http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html</a> say</p>
  
  <blockquote>
    <p>If libstdc++ is available as a shared library, and the -static option
    is not used, then this links against the shared version of libstdc++.</p>
  </blockquote>
  
  <p><strong>So, how can I make it link dynamically to stdc++?</strong></p>