Clang++ can't compile a simple hello world program.

This is the error message:
$ clang++ -v new.cpp
clang version 2.8 (branches/release_28 113675)
Target: i686-pc-mingw32
Thread model: posix
“C:/msys/local/bin/clang++.exe” -cc1 -triple i686-pc-mingw32 -S -disable-free -
disable-llvm-verifier -main-file-name new.cpp -mrelocation-model static -mdisabl
e-fp-elim -mconstructor-aliases -target-linker-version 2.20.51.20100613 -v -reso
urce-dir C:/msys/local/lib/clang/2.8 -ferror-limit 19 -fmessage-length 80 -fexce
ptions -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o C:/Windows
/TEMP/cc-000000.s -x c++ new.cpp
clang -cc1 version 2.8 based upon llvm 2.8rc hosted on i686-pc-mingw32
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.4.0/include”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.4.0/include/c++”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.4.0/include/c++/mingw
32”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.4.0/include/c++/backw
ard”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.3.0/include”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.3.0/include/c++”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.3.0/include/c++/mingw
32”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.3.0/include/c++/backw
ard”
ignoring nonexistent directory “/usr/local/include”
ignoring nonexistent directory “/usr/include”
#include “…” search starts here:
#include <…> search starts here:
c:/MinGW/lib/gcc/mingw32/4.5.0/include
c:/MinGW/lib/gcc/mingw32/4.5.0/include/c++
c:/MinGW/lib/gcc/mingw32/4.5.0/include/c++/mingw32
c:/MinGW/lib/gcc/mingw32/4.5.0/include/c++/backward
C:/msys/local/lib/clang/2.8/include
c:/mingw/include
End of search list.
“c:/MinGW/bin/g++.exe” -v -c -o C:/Windows/TEMP/cc-000001.o -x assembler C:/Win
dows/TEMP/cc-000000.s
Using built-in specs.
COLLECT_GCC=c:/MinGW/bin/g++.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/…/libexec/gcc/mingw32/4.5.0/lto-wrapper.exe
Target: mingw32
Configured with: …/gcc-4.5.0/configure --enable-languages=c,c++,ada,fortran,obj
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
mp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-r
untime-libs --disable-werror --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.5.0 (GCC)
COLLECT_GCC_OPTIONS=’-v’ ‘-c’ ‘-o’ ‘C:/Windows/TEMP/cc-000001.o’ ‘-shared-libgcc
’ ‘-mtune=i386’ ‘-march=i386’
c:/mingw/bin/…/lib/gcc/mingw32/4.5.0/…/…/…/…/mingw32/bin/as.exe -o C:/Wind
ows/TEMP/cc-000001.o C:/Windows/TEMP/cc-000000.s
COMPILER_PATH=c:/mingw/bin/…/libexec/gcc/mingw32/4.5.0/;c:/mingw/bin/…/libexec
/gcc/;c:/mingw/bin/…/lib/gcc/mingw32/4.5.0/…/…/…/…/mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/…/lib/gcc/mingw32/4.5.0/;c:/mingw/bin/…/lib/gcc/;c:/
mingw/bin/…/lib/gcc/mingw32/4.5.0/…/…/…/…/mingw32/lib/;c:/mingw/bin/…/lib/
gcc/mingw32/4.5.0/…/…/…/;/mingw/lib/
COLLECT_GCC_OPTIONS=’-v’ ‘-c’ ‘-o’ ‘C:/Windows/TEMP/cc-000001.o’ ‘-shared-libgcc
’ ‘-mtune=i386’ ‘-march=i386’
“c:/MinGW/bin/g++.exe” -v -o a.out C:/Windows/TEMP/cc-000001.o
Using built-in specs.
COLLECT_GCC=c:/MinGW/bin/g++.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/…/libexec/gcc/mingw32/4.5.0/lto-wrapper.exe
Target: mingw32
Configured with: …/gcc-4.5.0/configure --enable-languages=c,c++,ada,fortran,obj
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
mp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-r
untime-libs --disable-werror --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.5.0 (GCC)
COMPILER_PATH=c:/mingw/bin/…/libexec/gcc/mingw32/4.5.0/;c:/mingw/bin/…/libexec
/gcc/;c:/mingw/bin/…/lib/gcc/mingw32/4.5.0/…/…/…/…/mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/…/lib/gcc/mingw32/4.5.0/;c:/mingw/bin/…/lib/gcc/;c:/
mingw/bin/…/lib/gcc/mingw32/4.5.0/…/…/…/…/mingw32/lib/;c:/mingw/bin/…/lib/
gcc/mingw32/4.5.0/…/…/…/;/mingw/lib/
COLLECT_GCC_OPTIONS=’-v’ ‘-o’ ‘a.out’ ‘-shared-libgcc’ ‘-mtune=i386’ ‘-march=i38
6’
c:/mingw/bin/…/libexec/gcc/mingw32/4.5.0/collect2.exe -Bdynamic -u ___register
_frame_info -u ___deregister_frame_info -o a.out c:/mingw/bin/…/lib/gcc/mingw32
/4.5.0/…/…/…/crt2.o c:/mingw/bin/…/lib/gcc/mingw32/4.5.0/crtbegin.o -Lc:/min
gw/bin/…/lib/gcc/mingw32/4.5.0 -Lc:/mingw/bin/…/lib/gcc -Lc:/mingw/bin/…/lib/
gcc/mingw32/4.5.0/…/…/…/…/mingw32/lib -Lc:/mingw/bin/…/lib/gcc/mingw32/4.5.
0/…/…/… -L/mingw/lib C:/Windows/TEMP/cc-000001.o -lstdc++ -lmingw32 -lgcc_s -
lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmi
ngw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/…/lib/gcc/mingw3
2/4.5.0/crtend.o
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import)
c:/mingw/bin/…/lib/gcc/mingw32/4.5.0/…/…/…/…/mingw32/bin/ld.exe: Warning: t
ype of symbol _main' changed from 32 to 512 in C:/Windows/TEMP/cc-000001.o c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a uto-importing has been activated without --enable-auto-import specified on the c ommand line. This should work unless it involves constant data structures referencing symbols from auto-imported DLLs. C:/Windows/TEMP/cc-000001.o:fake:(.text+0x14): undefined reference to __dso_han
dle’
C:/Windows/TEMP/cc-000001.o:fake:(.text+0x3e): undefined reference to `__cxa_ate
xit’
collect2: ld returned 1 exit status
clang++: error: linker (via gcc) command failed with exit code 1 (use -v to see
invocation)

And here is the source file.
#include
using namespace std;
int main ()
{cout <<“hello world”;}
Do I have to use the llvm-link for the linking progress? If yes, then please tell me how do I get clang to use it.

See here for an explanation, and a patch:

http://llvm.org/bugs/show_bug.cgi?id=7276#c3

I have no idea why this isn't committed yet...

http://llvm.org/bugs/show_bug.cgi?id=7276#c3

I have no idea why this isn't committed yet...

Committed, thanks. For me it looks like slightly hacky, I don't pretty
much like OS checks in the driver.
Is it possible to move the check somewhere else? To some target-dependent part?

Out of curiosity, is this a known MinGW limitation?

Regards,
ismail

Probably, but this kind of stuff is done all over in Tools.cpp:

   // Enable -mconstructor-aliases except on darwin, where we have to
   // work around a linker bug; see <rdar://problem/7651567>.
   if (getToolChain().getTriple().getOS() != llvm::Triple::Darwin)
     CmdArgs.push_back("-mconstructor-aliases");

...

   // -fms-extensions=0 is default.
   if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
                    getToolChain().getTriple().getOS() == llvm::Triple::Win32))
     CmdArgs.push_back("-fms-extensions");

...

   // -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is
   // -the -cc1 default.
   bool NeXTRuntimeIsDefault =
     IsRewriter || getToolChain().getTriple().getOS() == llvm::Triple::Darwin;
   if (!Args.hasFlag(options::OPT_fnext_runtime, options::OPT_fgnu_runtime,
                     NeXTRuntimeIsDefault))
     CmdArgs.push_back("-fgnu-runtime");

I think it falls under the category "ugly but necessary". :slight_smile:

It doesn't seem to be a limitation, but simply unnecessary, as the
Microsoft VC runtime DLL already supplies its own mechanism for this
functionality.

See the discussion threads about this subject here:

   http://gcc.gnu.org/ml/gcc/2006-06/msg00747.html

and here:

   http://sourceforge.net/mailarchive/message.php?msg_name=E1G3KC2-0000da-HT%40sc8-sf-web1.sourceforge.net

I see, thanx!

I don't think this is quite the best method for this one in particular since it largely depends on
the target OS, but this is a good workaround for now for sure. I think, ideally, we're going to
want triple based configuration inside the driver eventually that can do things like set options etc.

Thanks for looking into this!

-eric