Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use libc++ on Windows?

Tags:

llvm

clang

Does libc++ support to be referenced/included and compiled on Windows with Clang/LLVM as native? For native, I mean no dependence on mingw and cygwin. I didn't find much doc on this but I believe it should be supported as clang for Windows has been released for a long time.

like image 628
Thomson Avatar asked Jan 04 '15 11:01

Thomson


1 Answers

Just an update. There is experimental support now (early 2018):

https://libcxx.llvm.org/docs/BuildingLibcxx.html#experimental-support-for-windows

(from the link)

Assming you have Ninja, and libcxx/llvm both checked out, libcxx can be compiled via

> cmake -G Ninja                                                                    ^
        -DCMAKE_MAKE_PROGRAM=/path/to/ninja                                         ^
        -DCMAKE_SYSTEM_NAME=Windows                                                 ^
        -DCMAKE_C_COMPILER=clang-cl                                                 ^
        -DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 --target=i686--windows"   ^
        -DCMAKE_CXX_COMPILER=clang-cl                                                ^
        -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 --target=i686--windows" ^
        -DLLVM_PATH=/path/to/llvm/tree                                              ^
        -DLIBCXX_ENABLE_SHARED=YES                                                  ^
        -DLIBCXX_ENABLE_STATIC=NO                                                   ^
        -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO                                     ^
        \path\to\libcxx
> /path/to/ninja cxx
 

As of 4/23/18, it will install into Program Files (x86) even if compiled for x86-64... (which can be done by changing i686 to x86_64 in the above).

Update in November 2020: I now use a package called llvm-mingw.

This package includes the clang compiler toolchain with wrappers to support various gcc style executables (e.g. gcc.exe, g++.exe, x86_64-w64-mingw32-gcc.exe) and can be used out of the box to compile against the mingw libc++ (you don't have to install mingw separately, the mingw libraries come with the package).

llvm-mingw is still young but has most features of mingw-w64. Features that are not implemented are:

  • lld linking to a dll (it's a feature of gnu ld, but not the llvm implementation)
  • There is no python wrapper for lldb so many IDEs can't use the debugger. Visual Studio Code seems to have it's own linkage so LLDB soes work with VS Code. People are working on this now.

Releases are available at the authors github repo. I have a binary installer available at my winlua.net site.

like image 94
Dinsdale Avatar answered Oct 12 '22 00:10

Dinsdale