C++ Standard Library on Windows

Hi there. For compiling C++ in Clang on Windows (8, in case it matters), what’s the recommended implementation of the standard library? I have msvc 2013 and MinGW 4.8.2, and I would be willing to checkout libc++ and compile it if it’s not still a world of hurt.

I tried copying the standard library from my MinGW installation to one of the paths Clang seemed to be looking for includes, but that didn’t work. The best I got was silent failure, after I butchered the directory structure in reaction to errors.

I hope this thread gets crawled by Google, because nothing recent shows up there.

For compiling clang I always have used MSVC. Just run the CMake configure step from a command window that has been set up for the version of Visual Studio you’re using (i.e., the vcvarsall.bat script has been run).

For building with clang, it should support either: clang-cl.exe looks for VS headers by default (again, assuming the environment is set up for VS), clang.exe looks for mingw headers. You can make clang.exe and clang++.exe use VS headers by setting the target to something like “-target i686-pc-windows-msvc”.

Currently I don’t think we have a solid preferred choice for a Windows standard C++ library to use with Clang. There are only tradeoffs and options:

MSVC’s STL: The 2013 version should work out of the box right now, but exceptions don’t work and you have to disable them with -D_HAS_EXCEPTIONS=0. This option is good if you want to link against other C++ code built with MSVC. I care about this config, so if you hit snags I’d like to know. There is a known issue with the C++11 threading headers and -D_HAS_EXCEPTIONS=0, which is described in this file in LLDB:
http://llvm.org/viewvc/llvm-project/lldb/trunk/test/make/uncaught_exception.h?view=markup

libstdc++ as distributed by MinGW64: This works and supports exceptions, but is ABI incompatible with C++ code compiled by MSVC, and ABI compatible with code compiled by GCC. Support for the new C++11 threading headers either relies on pthread emulation (I assume this is slow) or is non-existent.

libc++: I know people are using this on Windows on ARM. This isn’t really a battle tested configuration yet, though, so you would likely hit bugs. Saleem might be able to say more. I don’t think we have implementations of for Windows. You can use libc++ with Clang while targetting MSVC (–target=x86_64-pc-windows-msvc) or mingw (–target=x86_64-w64-windows-gnu), as long as you don’t pass standard library types across an ABI boundary.

Hope that helps.

Currently I don't think we have a solid preferred choice for a Windows
standard C++ library to use with Clang. There are only tradeoffs and
options:

MSVC's STL: The 2013 version should work out of the box right now, but
exceptions don't work and you have to disable them with
-D_HAS_EXCEPTIONS=0. This option is good if you want to link against other
C++ code built with MSVC. I care about this config, so if you hit snags I'd
like to know. There is a known issue with the C++11 threading headers and
-D_HAS_EXCEPTIONS=0, which is described in this file in LLDB:

http://llvm.org/viewvc/llvm-project/lldb/trunk/test/make/uncaught_exception.h?view=markup

Not works for me (clang 3.5 and VS 2013 U4):

clang++ -D_HAS_EXCEPTIONS=0 hello.cpp
hello-d5bfe1.o : error LNK2019: unresolved external symbol _Unwind_Resume
referenced in function "class std::basic_ostream<char,struct
std::char_traits<char> > & __cdecl std::operator<<<struct
std::char_traits<char> >(class std::basic_ostream<char,struct
std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@
@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z)
hello-d5bfe1.o : error LNK2001: unresolved external symbol
__gxx_personality_v0
hello-d5bfe1.o : error LNK2019: unresolved external symbol
__cxa_call_unexpected referenced in function "public: __cdecl
std::basic_ostream<char,struct std::char_traits<char>

::sentry::~sentry(void)" (??1sentry@?$basic_ostream@DU?$char_traits@D@std@

@@std@@QEAA@XZ)
a.out : fatal error LNK1120: 3 unresolved externals
clang++.exe: error: linker command failed with exit code 1120 (use -v to
see invocation)

clang++.exe defaults to targeting gcc’s ABI. Either set it to target msvc (e.g., ‘-target i686-pc-windows-msvc’) or use clang-cl.exe.

clang++ use g++ style(ABI),
In driver.cpp:
static const DriverSuffix DriverSuffixes = {
{“clang”, nullptr},
{“clang++”, “–driver-mode=g++”},
{“clang-c++”, “–driver-mode=g++”},
{“clang-cc”, nullptr},
{“clang-cpp”, “–driver-mode=cpp”},
{“clang-g++”, “–driver-mode=g++”},
{“clang-gcc”, nullptr},
{“clang-cl”, “–driver-mode=cl”},
{“cc”, nullptr},
{“cpp”, “–driver-mode=cpp”},
{“cl”, “–driver-mode=cl”},
{“++”, “–driver-mode=g++”},
};

If your must use Microsoft C++ STL Library, your should type clang-cl, it can be created by clang.exe (copy and rename).

Awesome, thanks all. I definitely have some tinkering to do now.