<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Clang is passing wrong library paths to the linker when cross compiling for MinGW-w64 on Linux" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24166&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=z4eI6Vrv6gcKPtQNxPMwbCZ_6Hv75qL3TVRi0uQsRQo&s=qdjKiJPsN3Tpj8IlzMks6z5V4fJcZ8nokWrT-rISDRg&e=">24166</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang is passing wrong library paths to the linker when cross compiling for MinGW-w64 on Linux
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.7
          </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>release blocker
          </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>t.poechtrager@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Trying to link a simple C++ program with Clang 3.7 on Linux:

$ cat test.cpp
#include <iostream>

int main() {
  std::cout << "Hello World" << std::endl;
}

$ /opt/compiler/llvm-3.7/bin/clang++ -target i686-w64-mingw32 -nostdinc
-fno-exceptions -isystem
/opt/compiler/llvm-trunk/bin/../lib/clang/3.7.0/include -isystem
/usr/i686-w64-mingw32/include -isystem /usr/i686-w64-mingw32/include/c++/5.1.0
-isystem /usr/i686-w64-mingw32/include/c++/5.1.0/backward -isystem
/usr/i686-w64-mingw32/include/c++/5.1.0/i686-w64-mingw32 -isysroot
/usr/i686-w64-mingw32 test.cpp 

Results in:

/tmp/test-d403b7.o:(.text+0xc): undefined reference to
`std::ios_base::Init::Init()'
/tmp/test-d403b7.o:(.text+0x39): undefined reference to
`std::ios_base::Init::~Init()'
/tmp/test-d403b7.o:(.text+0x4d): undefined reference to `std::cout'
/tmp/test-d403b7.o:(.text+0x5f): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::operator<<
<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&,
char const*)'
/tmp/test-d403b7.o:(.text+0x67): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/test-d403b7.o:(.text+0x6e): undefined reference to
`std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
clang-3.7: error: linker command failed with exit code 1 (use -v to see
invocation)

Examining the linker command shows '-L/usr/lib' is passed to the linker:

End of search list.
 "/usr/bin/i686-w64-mingw32-ld" -m i386pe -Bdynamic -o a.exe
/usr/i686-w64-mingw32/lib/crt2.o
/usr/lib64/gcc/i686-w64-mingw32/5.1.0/crtbegin.o
-L/usr/lib64/gcc/i686-w64-mingw32/5.1.0 --->> -L/usr/lib <<---
-L/usr/i686-w64-mingw32/lib -L/usr/i686-w64-mingw32/sys-root/mingw/lib
/tmp/test-102ff8.o -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex
-lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc
-lmoldname -lmingwex -lmsvcrt /usr/lib64/gcc/i686-w64-mingw32/5.1.0/crtend.o

Debug output from the linker:

[...]
attempt to open /usr/lib64/gcc/i686-w64-mingw32/5.1.0/libstdc++.dll.a failed
attempt to open /usr/lib64/gcc/i686-w64-mingw32/5.1.0/stdc++.dll.a failed
attempt to open /usr/lib64/gcc/i686-w64-mingw32/5.1.0/libstdc++.a failed
attempt to open /usr/lib64/gcc/i686-w64-mingw32/5.1.0/stdc++.lib failed
attempt to open /usr/lib64/gcc/i686-w64-mingw32/5.1.0/libstdc++.dll failed
attempt to open /usr/lib64/gcc/i686-w64-mingw32/5.1.0/stdc++.dll failed
attempt to open /usr/lib64/gcc/i686-w64-mingw32/5.1.0/libstdc++.a failed
attempt to open /usr/lib/libstdc++.dll.a failed
attempt to open /usr/lib/stdc++.dll.a failed
attempt to open /usr/lib/libstdc++.a succeeded  <----

I also tried to add '-isysroot /usr/i686-w64-mingw32', but it's no help either.</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>