[cfe-dev] Building with mingw64 on Windows issue
Martin Storsjö via cfe-dev
cfe-dev at lists.llvm.org
Thu Nov 29 05:19:57 PST 2018
Hi Maarten,
On Wed, 28 Nov 2018, Maarten Verhage via cfe-dev wrote:
> Ok, my desire is to be able to build the LLVM/clang system with mingw64 on
> Windows 7, 64bit. I’m currently stuck on an error that the shared library
> c++abi cannot be found. Below is shown how I got there.
>
> I wasn’t able to find build guidelines specific for mingw64. But left to my
> own devices I believe I made some progress.
FWIW, I regularly compile libcxx/libcxxabi for mingw, mainly with clang as
a cross compiler from linux though, but the same build process also mostly
works on msys/mingw.
I don't build libcxx/libcxxabi as part of the main llvm build, but I build
them standalone outside of this, when I have clang set up as a cross
compiler (building them for a number of different architectures). Here's
the script I use for building that:
https://github.com/mstorsjo/llvm-mingw/blob/master/build-libcxx.sh
I'm told it's supposed to be possible to cross-build the runtime libraries
inside of the llvm tree with the newly built clang as cross compiler, but
I haven't tried to figure out how to make this work for my setup yet.
> I downloaded MinGW-W64 GCC-8.1.0 from here:
> https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/8.1.0/threads-win32/
>
> There I selected: x86_64-win32-seh for download.
>
> I got llvm and clang plus the llvm libc++ standard library and libc++abi as
> suggested on the getting started webpage.
>
> I put the mingw-w64 bin folder in my PATH.
> gcc -dumpversion
> shown 8.1.0
>
> I already figured out a way to compile the thread_win32.cpp file located in
> <llvm_path>/projects/libcxx/src/support/win32. With the following
> adjustments (hacks) to CMakeLists.txt files.
>
> In C:\dev\llvm\projects\libcxx\CMakeLists.txt
> added section at line 65:
> if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
> set(LIBCXX_TARGETING_GNU ON)
> message(STATUS "Configuring for GNU")
> else()
> set(LIBCXX_TARGETING_GNU OFF)
> endif()
>
> Then in C:\dev\llvm\projects\libcxx\lib\CMakeLists.txt
> added section at line 132
> if (LIBCXX_TARGETING_GNU)
> message( STATUS "GNU Configuration here" )
> add_compile_flags(-D_LIBCPP_HAS_THREAD_API_WIN32 -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
> -D_WIN32_WINNT=0x0600)
> endif()
Forcing the win32 thread api probably is good; I do the same, to avoid
preferring winpthreads if they happen to be available. Is there any case
where using winpthreads over the native win32 threads actually would be
beneficial though, should we change the priority order there to avoid
having to force it here?.
Forcing -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS isn't ideal if you want
to be able to build libcxx as a DLL as well.
Adding -D_WIN32_WINNT=0x0600 sounds sensible to me.
> My cmake command line is:
> cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ^
> -DLLVM_PATH=C:\dev\llvm ^
> -DLIBCXX_CXX_ABI=libcxxabi ^
> -DLIBCXX_CXX_ABI_INCLUDE_PATHS=C:\dev\llvm\projects\libcxxabi\include ^
> -S C:\dev\llvm\projects\libcxx -B
> T:\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\build >
> cmake_result.txt 2>&1
>
> cmake_result.txt is attached.
>
> note: T: is some ramdrive disk made with the tool Arsenal-Image-Mounter.
>
> Then:
> mingw32-make --directory=T:\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\build
> -f Makefile cxx > build_result.txt 2>&1
>
> build_result.txt also attached. Line 204 in that file is the error: "cannot
> find –lc++abi".
>
> I think somehow in the folder:
> T:\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\build\lib\abi
> the Makefile is not processed.
>
> In the non-abi folder:
> T:\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\build\lib\CMakeFiles I
> can find a full folder cxx_objects.dir. So libc++ is compiled.
>
> I’d love if some expert on the building process could help me out here. I
> hope I’ve communicated all the relevant details for this issue.
In my builds, there's quite a bit of fiddling between libcxxabi and libcxx
to make them find each other, have a look at the script I linked earlier.
It's not exactly very clean, but it works for me for now at least.
// Martin
More information about the cfe-dev
mailing list