<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">I want to accomplish a
      c++ executable that links to another c++ library of my own without
      a libstdc++ dependency. I can create such a c++ executable without
      the library without difficulty. But as soon as I link it to my
      library, the executable now has a libstdc++ dependency. A
      requirement is to NOT need to copy libstdc++6.dll (or any other
      .dll) onto Windows.</p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">I'm building on Linux
      (Centos 7) using the latest mingw64 (x86_64-w64-mingw32-gcc (GCC)
      4.9.3), cross compiling to Windows. Building on MSYS2/MingW has
      the same unwanted result.</p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">In the example below,
      two lines are marked "COMMENT ME OUT": one in hello_c/main.cpp and
      the other in hello_c/CMakeLists.txt. If you comment these out, the
      reference to the hello_lib library is removed; the project builds
      and the executable executes on Windows 10 without a libstdc++
      dependency. If you uncomment the two lines, the function in the
      hello_lib library is linked in; the project builds, but won't
      execute on Windows 10 due to the libstdc++ dependency. (Note: in
      powershell it silently fails, in an old-school dos/cmd box it
      displays an error message.)</p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">The example has this
      structure (contents below):</p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">* hello_lib/library.cpp<br>
      * hello_lib/library.h<br>
      * hello_lib/CMakeLists.txt<br>
      * hello_c/main.cpp<br>
      * hello_c/CMakeLists.xt<br>
      * buildme.sh <br>
      * toolchain.cmake<br>
    </p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">###### BEGIN CODE ######<br>
      ## hello_lib/library.h:<br>
      int hello();<br>
      <br>
      ## hello_lib/library.cpp:<br>
      #include "library.h"<br>
      int hello() {<br>
          return 666;<br>
      }<br>
      <br>
      ## hello_lib CMakeLists.txt:<br>
      cmake_minimum_required(VERSION 3.13)<br>
      project(hello_lib)<br>
      set(CMAKE_CXX_STANDARD 11)<br>
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -static-libgcc
      -static-libstdc++")<br>
      add_library(hello_lib STATIC library.cpp)<br>
      <br>
      ## hello_c/main.cpp:<br>
      #include <iostream><br>
      #include "../hello_lib/library.h"<br>
      int main() {<br>
          std::cout << "Hello, world" << std::endl;<br>
          //COMMENT ME OUT:<br>
          printf("x = %d\n", hello());<br>
          return 0;<br>
      }<br>
      <br>
      ## hello_c CMakeLists.txt:<br>
      cmake_minimum_required(VERSION 3.13)<br>
      project(hello_c)<br>
      set(CMAKE_CXX_STANDARD 11)<br>
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -static-libgcc
      -static-libstdc++")<br>
      link_directories(../hello_lib/cmake-build-debug)<br>
      add_executable(hello_c main.cpp)<br>
      # COMMENT ME OUT:<br>
      target_link_libraries(hello_c -static-libgcc -static-libstdc++
      libhello_lib.a)<br>
      <br>
      ## buildme.sh:<br>
      #!/bin/bash<br>
      set -e<br>
      for i in hello_lib hello_c<br>
      do<br>
          rm -rf $i/cmake-build-debug<br>
          mkdir $i/cmake-build-debug<br>
          pushd $i/cmake-build-debug<br>
          # For building Win64 on Linux (with MinW64):<br>
          cmake .. -DCMAKE_TOOLCHAIN_FILE="../toolchain.cmake"
      -DCMAKE_BUILD_TYPE=Debug<br>
          # For building Win64 on Win64/MSYS2/MinW64:<br>
          #cmake .. -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug<br>
          # For building Linux on Linux<br>
          #cmake .. -DCMAKE_BUILD_TYPE=Debug<br>
          make<br>
          popd<br>
      done<br>
      <br>
      ## toolchain.cmake:<br>
      set(CMAKE_SYSTEM_NAME Windows)<br>
      set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)<br>
      set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)<br>
      set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)<br>
      set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)<br>
      set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})<br>
    </p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;">###### END CODE ######</p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;"><span style="color:
        rgb(36, 39, 41); font-family: Arial, "Helvetica Neue",
        Helvetica, sans-serif; font-size: 15px; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: left; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial; display: inline !important; float: none;">With both
        MingW64 on Linux, and MingW64/MSYS2 on Windows 10, I get the
        libstdc++ dependency when I link with the 'hello_lib' library.
        In both cases if I comment out the reference to hello_lib, the
        libstdc++ dependency is eliminated.</span></p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;"><span style="color:
        rgb(36, 39, 41); font-family: Arial, "Helvetica Neue",
        Helvetica, sans-serif; font-size: 15px; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: left; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial; display: inline !important; float: none;">I would be
        very grateful for your insight!</span></p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;"><span style="color:
        rgb(36, 39, 41); font-family: Arial, "Helvetica Neue",
        Helvetica, sans-serif; font-size: 15px; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: left; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial; display: inline !important; float: none;">William
        Zeitler</span></p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;"><span style="color:
        rgb(36, 39, 41); font-family: Arial, "Helvetica Neue",
        Helvetica, sans-serif; font-size: 15px; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: left; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
        255); text-decoration-style: initial; text-decoration-color:
        initial; display: inline !important; float: none;"><br>
      </span></p>
    <p style="margin: 0px 0px 1em; padding: 0px; border: 0px;
      font-style: normal; font-variant-ligatures: normal;
      font-variant-caps: normal; font-variant-numeric: inherit;
      font-variant-east-asian: inherit; font-weight: 400; font-stretch:
      inherit; line-height: inherit; font-family: Arial, "Helvetica
      Neue", Helvetica, sans-serif; font-size: 15px;
      vertical-align: baseline; box-sizing: inherit; clear: both; color:
      rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align:
      left; text-indent: 0px; text-transform: none; white-space: normal;
      widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
      background-color: rgb(255, 255, 255); text-decoration-style:
      initial; text-decoration-color: initial;"><br>
    </p>
    <p>
      <style type="text/css">
                body,div,table,thead,tbody,tfoot,tr,th,td,p { font-family:"Liberation Sans"; font-size:x-small }
                a.comment-indicator:hover + comment { background:#ffd; position:absolute; display:block; border:1px solid black; padding:0.5em;  } 
                a.comment-indicator { background:red; display:inline-block; border:1px solid black; width:0.5em; height:0.5em;  } 
                comment { display:none;  } 
        </style></p>
  </body>
</html>