I just downloaded the CLang sources, made a Visual C++ 10 IDE workspace by using CMake, and built everything from Visual C++ 10.0 (express).
Now I get a bunch of linker errors on hello world:
d:\dev\test> type con >foo.cpp #include <iostream> using namespace std; int main() { cout << "Hello, cling-clong world!" << endl; } ^Z d:\dev\test> clang++ foo.cpp foo-839435.o : error LNK2019: unresolved external symbol __ZSt4cout referenced in function _main foo-839435.o : error LNK2019: unresolved external symbol __ZdlPv referenced in function __ZNSt14error_categoryD0Ev foo-839435.o : error LNK2019: unresolved external symbol __ZSt18uncaught_exceptionv referenced in function __ZNSo6sentry D2Ev foo-839435.o : error LNK2019: unresolved external symbol ___cxa_rethrow referenced in function __ZNSt8ios_base5clearEib foo-839435.o : error LNK2019: unresolved external symbol ___cxa_allocate_exception referenced in function __ZNSt8ios_base5clearEib foo-839435.o : error LNK2019: unresolved external symbol ___cxa_throw referenced in function __ZNSt8ios_base5clearEib foo-839435.o : error LNK2019: unresolved external symbol __ZSt17iostream_categoryv referenced in function __ZSt15make_er
So what can I do about it?
Clang/LLVM support for both CMake and MSBuild projects is available in Visual Studio 2019 and Visual Studio 2022. You can use Visual Studio 2019 version 16.2 and later with Clang/LLVM to edit, build, and debug C++ Visual Studio projects (MSBuild) that target Windows or Linux.
Clang can be configured to use one of several different linkers: GNU ld. GNU gold. LLVM's lld.
for clang , compiles code as C. for clang++ , compiles code as C++
If you want to experiment with Clang on Windows, I suggest using a MinGW built version, like the one I provide here (or build it yourself using your favourite MinGW toolchain):
32-bit
64-bit
You will need both the gcc
and clang
packages (those without linux/mac/cygwin suffixes) and extract them to the same directory. Clang uses gcc to link, and can link to GCC's libstdc++, pretty much giving you access to the C++ standard library. Exceptions work for the 32-bit version. I haven't had any luck with debug info though.
Work is being done to bring better MS support to Clang, but it's a slowly progressing task.
I think there is a misunderstanding here.
Clang is (slowly) being taught how to parse MFC headers. As far as I know, François Pichet is about alone on this project but there are only a few errors in the whole headers lot (!), and obviously the standard library shipped with VC++ parsing has been completed a long time ago.
However, this is about AST generation, not Code Generation. Clang is currently unable to properly generate code to interact with VC++ libraries. Not only is the name mangling incomplete, but the ABI is still being shaped (there have been numerous patches in the last 2 months to get the right padding/alignment) and there is a long standing issue with exceptions.
If you wish to use Clang on Windows, you should use MinGW or MinGW64, see ruben's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With