[cfe-dev] Building with mingw64 on Windows issue

Maarten Verhage via cfe-dev cfe-dev at lists.llvm.org
Fri Nov 30 08:04:18 PST 2018


Hi Martin,

> 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.

Thanks for sharing your advice as well as that build script. I’m able to 
copy-and-paste the relevant portions to make progress in building llvm/clang 
in the windows command prompt.

First I tried to build llvm with clang in the tools folder but with an empty 
projects folder. This failed because mingw64 gcc-8.1.0 doesn’t have support 
for std::mutex. But libcxx does contain std::mutex so I decided to get 
libcxx to build before this. As libcxx needs to link against libcxxabi I 
decided to build libcxxabi first.

I realized the hacks I had in the CMakeLists.txt files could be eliminated 
by specifying the defines on the command line of the cmake call.

I’m doing a single library at once. So first a cmake call to generate the 
Mingw makefile for libcxxabi, then the mingw call to build the Makefile for 
libcxxabi.

Ok specifically:
cmake -G "MinGW Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_SYSTEM_NAME=Windows ^
-DLIBCXXABI_ENABLE_SHARED=OFF ^
-DLIBCXXABI_LIBCXX_INCLUDES=..\..\llvm\projects\libcxx\include ^
-DLIBCXXABI_ENABLE_EXCEPTIONS=ON ^
-DCMAKE_CXX_FLAGS="-D_LIBCPP_BUILDING_LIBRARY -U_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS 
 -D_LIBCPP_HAS_THREAD_API_WIN32" ^
-S..\..\llvm\projects\libcxxabi ^
-BT:\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\build\libcxxabi > 
libcxxabi_cmake_result.txt 2>&1

I’m getting:
“CMake Warning at cmake/Modules/HandleOutOfTreeLLVM.cmake:57 (message):
  UNSUPPORTED LIBCXXABI CONFIGURATION DETECTED: llvm-config not found and
  LLVM_PATH not defined.

  Reconfigure with -DLLVM_CONFIG_PATH=path/to/llvm-config or
  -DLLVM_PATH=path/to/llvm-source-root.
Call Stack (most recent call first):
  cmake/Modules/HandleOutOfTreeLLVM.cmake:81 (find_llvm_parts)
  cmake/Modules/HandleOutOfTreeLLVM.cmake:140 (configure_out_of_tree_llvm)
  CMakeLists.txt:29 (include)”

Is this something I can tolerate? Your script shows neither of these 
defines. So I assume you also have these warnings.

Then:
mingw32-make ^
--directory=T:\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\build\libcxxabi 
 -f Makefile > libcxxabi_build_result.txt 2>&1

A bunch of warnings like:
warning: unknown conversion type character 'L' in format [-Wformat=]

worrisome?

But I do get the libc++abi.a library out of it.

So continuing with libcxx:
cmake -G "MinGW Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_SYSTEM_NAME=Windows ^
-DLIBCXX_HAS_WIN32_THREAD_API=ON ^
-DLIBCXX_ENABLE_SHARED=ON ^
-DLIBCXX_ENABLE_STATIC=OFF ^
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE ^
-DLIBCXX_ENABLE_EXCEPTIONS=ON ^
-DLIBCXX_CXX_ABI=libcxxabi ^
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=..\..\llvm\projects\libcxxabi\include ^
-DLIBCXX_CXX_ABI_LIBRARY_PATH=T:\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\build\libcxxabi\lib 
^
-DCMAKE_CXX_FLAGS="-D_LIBCPP_BUILDING_LIBRARY -D_WIN32_WINNT=0x0600" ^
-S..\..\llvm\projects\libcxx ^
-BT:\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\build\libcxx > 
libcxx_cmake_result.txt 2>&1

Get the same warning about llvm-config not found.

Then:
mingw32-make ^
--directory=T:\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\build\libcxx 
^
-f Makefile > libcxx_build_result.txt 2>&1

The good news is that libc++.dll.a library is build. But right after that: 
[ 95%] Linking CXX shared library libc++.dll fails. This is followed by a 
couple of errors like:
undefined reference to `__imp___cxa_decrement_exception_refcount'

all following errors are exception related.

however looking in the cxxabi_objects.dir folder of libcxxabi I do see the 
file cxa_exception.cpp.obj

Did I missed some crucial define somewhere? You know even when I look at the 
official documentation on:
https://libcxx.llvm.org/docs/BuildingLibcxx.html
, it is hard for me to judge whether a define is needed for my goals.

In general my objective with clang is to be able to use the Windows API 
functionality that mingw64 provides while having clang as the compiler. I 
believe there needs to be a further step to build the mingw provided win32 
code with clang is it?

Still any suggestions to make progress building clang are welcome!

Thanks I appreciate.
Maarten

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

Well as for this world citizen (me) your script looks great! :) 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: libcxxabi_build_result.txt
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181130/fa520ed7/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: libcxxabi_cmake_result.txt
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181130/fa520ed7/attachment-0001.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: libcxx_cmake_result.txt
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181130/fa520ed7/attachment-0002.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: libcxx_build_result.txt
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181130/fa520ed7/attachment-0003.txt>


More information about the cfe-dev mailing list