[LLVMbugs] [Bug 24166] New: Clang is passing wrong library paths to the linker when cross compiling for MinGW-w64 on Linux

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jul 17 10:28:12 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24166

            Bug ID: 24166
           Summary: Clang is passing wrong library paths to the linker
                    when cross compiling for MinGW-w64 on Linux
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: t.poechtrager at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150717/42a97b84/attachment.html>


More information about the llvm-bugs mailing list