12

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?

5 Answers 5

5

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):

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I think this is "the solution", except that the information you provide about exceptions means that an even better solution is to not install the thing (yet). Thanks anyway.
This does not resolve the problem using clang compiled with VC. Using MinGW is just putting the issue aside. Unfortunately libc (libcxx.llvm.org) does not support Windows platform, which is the real problem here.
@Archie: libcxx can be built on Windows with MinGW-w64 built Clang (I took care of that), but that does not get you everything you need, like exception handling, low-level runtime functions, etc... There are two sides here: 1) get Clang to mangle like MSVC++, along with generating the same rtti and exception handling code, and 2) Make Clang mirror GCC and link to its libraries, which I did and it works for 32-bit. Making MSVC built Clang work will require serious support in LLVM for MSVC style code generation, which is just not there right now.
2

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.

Comments

1

Unlike MinGW gcc, clang does not include the glibc library, so by default, it has no standard library or whatsoever. I don't know how to use the Visual C++ standard libary with it, but its pretty clear from what you post, that by default it produces symbols like gcc, so you need to use it with glibc or newlib...

And either you specify the the libary path with -Ldirectory to the .lib files (or .a for glibc), or put them into one of default clang search pathes (run: clang -v -x c++ -fsyntax-only some file to see them.)

1 Comment

MinGW does not include glibc, and neither is a missing system C library the problem here.
1

Use clang++ only to compile .cpp and then instead of MS link try ld linker. Works for me.

Comments

0

Clang/LLVM's supports for Windows are still not perfect. Try to include this option: -Xclang -cxx-abi -Xclang microsoft. But, I'm not sure whether it makes work correctly.

1 Comment

Thanks, but I got an ICE (Internal Compiler Error). Which didn't know that it was an ICE. The compiler just crashed, by calling abort(). And told me that it "Can't yet mangle constructors!" UNREACHABLE executed at D:\dev\tools\llvm\tools\clang\lib\AST\MicrosoftMangle.cpp:1172! clang++: error: clang frontend command failed with exit code 3 (use -v to see invocation)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.