<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Cannot compile with `-static` when using exceptions with target x86_64-w64-windows-gnu"
   href="https://bugs.llvm.org/show_bug.cgi?id=34122">34122</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Cannot compile with `-static` when using exceptions with target x86_64-w64-windows-gnu
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dario.ostuni@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18947" name="attach_18947" title="program.cpp">attachment 18947</a> <a href="attachment.cgi?id=18947&action=edit" title="program.cpp">[details]</a></span>
program.cpp

When trying to compile `program.cpp` (in attachment) with `-static` for target
x86_64-w64-windows-gnu this is what happens:
```
$ x86_64-w64-mingw32-clang++ -o program.exe -pthread -static -v program.cpp
clang version 6.0.0 (trunk 310227)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/clang-6.0" -cc1 -triple x86_64-w64-windows-gnu -emit-obj -mrelax-all
-disable-free -disable-llvm-verifier -discard-value-names -main-file-name
program.cpp -static-define -mrelocation-model pic -pic-level 2 -mthread-model
posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables
-target-cpu x86-64 -momit-leaf-frame-pointer -v -dwarf-column-info
-debugger-tuning=gdb -nostdsysteminc -nobuiltininc -resource-dir
/usr/lib/clang/6.0.0 -isystem /usr/bin/../lib/clang/6.0.0/include -isystem
/usr/x86_64-w64-mingw32/include/c++/7.1.1 -isystem
/usr/x86_64-w64-mingw32/include/c++/7.1.1/x86_64-w64-mingw32 -isystem
/usr/x86_64-w64-mingw32/include -fdeprecated-macro -fdebug-compilation-dir /tmp
-ferror-limit 19 -fmessage-length 132 -pthread -fno-use-cxa-atexit
-fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -o /tmp/program-26420f.o -x c++ program.cpp
clang -cc1 version 6.0.0 based upon LLVM 6.0.0svn-r310227 default target
x86_64-unknown-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
 /usr/bin/../lib/clang/6.0.0/include
 /usr/x86_64-w64-mingw32/include/c++/7.1.1
 /usr/x86_64-w64-mingw32/include/c++/7.1.1/x86_64-w64-mingw32
 /usr/x86_64-w64-mingw32/include
End of search list.
 "/usr/bin/x86_64-w64-mingw32-ld" -m i386pep -Bstatic -o program.exe
/usr/x86_64-w64-mingw32/lib/crt2.o
/usr/lib/gcc/x86_64-w64-mingw32/7.1.1/crtbegin.o
-L/usr/lib/gcc/x86_64-w64-mingw32/7.1.1 -L/usr/lib/gcc/x86_64-w64-mingw32/7.1.1
-L/usr/x86_64-w64-mingw32/lib -L/usr/lib
-L/usr/x86_64-w64-mingw32/sys-root/mingw/lib /tmp/program-26420f.o -lstdc++
--start-group -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lpthread
-ladvapi32 -lshell32 -luser32 -lkernel32 --end-group
/usr/lib/gcc/x86_64-w64-mingw32/7.1.1/crtend.o
/tmp/program-26420f.o:(.text+0xa2): undefined reference to
`__imp___dynamic_cast'
/tmp/program-26420f.o:(.text+0xb7): undefined reference to
`__imp___cxa_bad_cast'
/tmp/program-26420f.o:(.text+0xf1): undefined reference to
`__imp___cxa_begin_catch'
/tmp/program-26420f.o:(.text+0x146): undefined reference to
`__imp___cxa_end_catch'
/tmp/program-26420f.o:(.text+0x161): undefined reference to
`__imp___cxa_end_catch'
/tmp/program-26420f.o:(.text[__clang_call_terminate]+0x7): undefined reference
to `__imp___cxa_begin_catch'
clang-6.0: error: linker command failed with exit code 1 (use -v to see
invocation)
```
There is an associated issue on github:
<a href="https://github.com/tpoechtrager/wclang/issues/32">https://github.com/tpoechtrager/wclang/issues/32</a>

The author of wclang has some insight of what is happening here:
<a href="https://github.com/tpoechtrager/wclang/issues/32#issuecomment-320678320">https://github.com/tpoechtrager/wclang/issues/32#issuecomment-320678320</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>