CLang + iostreams on Windows = problems?

Hi all, I am new to Clang/LLVM and this list, so apologies if this is the wrong channel (also: now accepting redirection to the proper channel!)

I enlisted in the LLVM and Clang branches and followed the web page instructions on getting them building (which worked without a hitch, kudos). I then tried compiling a dead simple hello world program and ran into some linker errors I can’t quite figure out. I reduced the necessary code to cause some of the errors down to this:

#include <stdio.h>
#include
int main(int argc, char **argv)
{
return 0;
}

Once I #include iostream, things go bad. Specifically I see this

HelloWorld-778227.o : error LNK2019: unresolved external symbol __ZdlPv referenced in function __ZNSt14error_categoryD0Ev
HelloWorld-778227.o : error LNK2001: unresolved external symbol ___cxa_pure_virtual
HelloWorld-778227.o : error LNK2001: unresolved external symbol __ZTVN10__cxxabiv117__class_type_infoE

I understand the linker can’t find these things, I guess I just don’t understand where they are supposed to be coming from. I invoke clang with specific directions to link with both libcmt.lib and libcpmt.lib which should include all the CRT/STL stuff I need (I think). Specifically I invoked this (and have included the output):

c:\build>clang HelloWorld.cpp -o HelloWorld.exe -Xlinker “c:\Program Files\Microsoft Visual Studio 10.0\VC\lib\LIBCPMT.LIB” -v

clang version 3.0 (trunk 140598)

Target: i686-pc-win32
Thread model: posix

“c:/build/bin/debug/clang.exe” -cc1 -triple i686-pc-win32 -emit-obj -mrelax-all -disable-free -main-file-name HelloWorld.cpp
-mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -momit-leaf-frame-pointer
-v -resource-dir c:/build/bin/debug…\lib\clang\3.0 -fmodule-cache -path C:\Users\rmolden\AppData\Local\Temp\clang-module-cache
-fdeprecated-macro -ferror-limit 19 -fmessage-length 80 -fms-extensions -fms-compatibility -fmsc-version=1300 -fdelayed-template-parsing
-fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o C:/Users/rmolden/AppData/Local/Temp/HelloWorld-778227.o
-x c++ HelloWorld.cpp

clang -cc1 version 3.0 based upon llvm 3.0 hosted on i686-pc-win32

ignoring nonexistent directory “/usr/local/include”
ignoring nonexistent directory “/usr/include”
#include “…” search starts here:
#include <…> search starts here:
C:\Program Files\Microsoft Visual Studio 10.0\VC\include
C:\Program Files\Microsoft SDKs\Windows\v7.1\include
End of search list.

“C:/Program Files/Microsoft Visual Studio 10.0/VC/BIN/link.exe” -out:HelloWorld.exe -defaultlib:libcmt -nologo
C:/Users/rmolden/AppData/Local/Temp/HelloWorld-778227.o c:\Program Files\Microsoft Visual Studio 10.0\VC\lib\LIBCPMT.LIB

clang: error: linker command failed with exit code 1120 (use -v to see invocation)

HelloWorld-778227.o : error LNK2019: unresolved external symbol __ZdlPv referenced in function __ZNSt14error_categoryD0Ev
HelloWorld-778227.o : error LNK2001: unresolved external symbol ___cxa_pure_virtual
HelloWorld-778227.o : error LNK2001: unresolved external symbol __ZTVN10__cxxabiv117__class_type_infoE
HelloWorld.exe : fatal error LNK1120: 3 unresolved externals

I searched Bugzilla and the internets, and apart from a blog posting from someone else complaining about iostreams with clang on Windows I wasn’t able to find anything helpful.

At this point I am assuming the answer is some variation of ‘you’re doing it wrong’, but I can’t figure what ‘it’ is, or how one goes about ‘doing it right’, so any help/pointers/hints would be much appreciated!

Ryan

Clang's implementation of MSVC's C++ ABI is still very minimal, and it's unlikely that you'll be able to get Clang to produce code which would interoperate correctly with Microsoft's standard library, even if it linked successfully. We'd *love* to see more work on this, though.

That said, it looks like Clang is producing code for the Itanium ABI; it's probably compiling as if it were targeting mingw.

John.