Linking errors on combining Clang compiler and Visual Studio 2010 linker

I’ve successfully build Clang compiler on Windows and successfully compiled a simple pure C hello world application. But when I’ve tried to compile the following simple C++ application I got a bunch of linking errors from Visual Studio 2010 linker.

The content of “sample.cpp”:

#include

int main() {
std::vector v;
v.push_back( 0 );
return v.front();
}

Then I’ve typed in the Visual Studio 2010 command line:

clang sample.cpp -o sample.exe -v

And I’ve got this:

clang version 3.0 (trunk)
Target: i686-pc-win32
Thread model: posix
“C:/Development/Clang/build/bin/Release/clang.exe” -cc1 -triple i686-pc-win32 -
emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name sample
.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-ali
ases -momit-leaf-frame-pointer -v -resource-dir C:/Development/Clang/build/bin/R
elease..\lib\clang\3.0 -ferror-limit 19 -fmessage-length 80 -fcxx-exceptions -f
exceptions -fms-extensions -fmsc-version=1300 -fgnu-runtime -fdiagnostics-show-o
ption -fcolor-diagnostics -o C:/DOCUME~1/Lokken/LOCALS~1/Temp/cc-633218.o -x c++
sample.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 “C:/Development/Clang/build/bin/Release/…/lib/cl
ang/3.0/include”
ignoring nonexistent directory “C:\Program Files\Microsoft Visual Studio 10.0\VC
\PlatformSDK\Include”
ignoring nonexistent directory “/usr/include”
#include “…” search starts here:
#include <…> search starts here:
C:\Program Files\Microsoft Visual Studio 10.0\VC\include
End of search list.
“C:/Program Files/Microsoft Visual Studio 10.0/VC/BIN/link.exe” -out:sample.exe
-defaultlib:libcmt -nologo C:/DOCUME~1/Lokken/LOCALS~1/Temp/cc-633218.o
cc-633218.o : error LNK2019: unresolved external symbol __ZSt14_Xlength_errorPKc
referenced in function __ZNKSt6vectorIiSaIiEE5_XlenEv
cc-633218.o : error LNK2019: unresolved external symbol __ZdlPv referenced in fu
nction __ZNSaIiE10deallocateEPij
cc-633218.o : error LNK2019: unresolved external symbol __Znwj referenced in fun
ction _ZSt9_AllocateIiEPT_jS1
cc-633218.o : error LNK2019: unresolved external symbol ___cxa_allocate_exceptio
n referenced in function _ZSt9_AllocateIiEPT_jS1
cc-633218.o : error LNK2019: unresolved external symbol ___cxa_throw referenced
in function _ZSt9_AllocateIiEPT_jS1
cc-633218.o : error LNK2019: unresolved external symbol __ZNSt9exceptionD2Ev ref
erenced in function __ZNSt9bad_allocD2Ev
cc-633218.o : error LNK2019: unresolved external symbol __ZNSt9exceptionC2ERKPKc
referenced in function __ZNSt9bad_allocC2EPKc
cc-633218.o : error LNK2001: unresolved external symbol __ZTVN10__cxxabiv120__si
_class_type_infoE
cc-633218.o : error LNK2001: unresolved external symbol __ZTISt9exception
cc-633218.o : error LNK2001: unresolved external symbol __ZNKSt9exception4whatEv

Is this a bug or am I doing something wrong?

It is not a bug and you are not doing anything wrong. More like
unimplemented features.
It is just that clang cannot use the MSVC C++ runtime libs yet because
of C++ name mangling issues.

It's worse than that. Almost the entire ABI is unimplemented. Even if we
fixed the name mangling issues (which is easy, and already started in
Clang), we still have to make sure that method calls, class layouts,
etc. are compatible with MSVC. Luckily for you, I'm planning to fix that
this summer (for my GSoC project).

Chip