Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using non-MinGW Clang to build for MinGW ABI #8072

Closed
triplef opened this issue Mar 6, 2021 · 4 comments
Closed

Using non-MinGW Clang to build for MinGW ABI #8072

triplef opened this issue Mar 6, 2021 · 4 comments

Comments

@triplef
Copy link

triplef commented Mar 6, 2021

This is not strictly an issue with MinGW packages, but related – please let me know if there’s a better place to post this question. Thanks!

I am trying to use the non-MinGW Windows Clang/LLVM release (e.g. installed via choco install llvm) to build a CMake project for the MinGW ABI (e.g. target triple x86_64-w64-mingw64), and am looking for a list of required CMake options to match the MinGW Clang package (which is built with a number of patches) as closely as possible.

So far I’m using:

  • CMAKE_C_COMPILER_TARGET/CMAKE_CXX_COMPILER_TARGET/CMAKE_ASM_COMPILER_TARGET=x86_64-w64-mingw64
  • CMAKE_SYSROOT=/mingw64

Unfortunately this does not seem to be sufficient for a certain try_compile() in my CMake project, even though I’m manually forwarding the above options to try_compile() using the CMAKE_FLAGS option, as I’m getting a number of linker errors outlined in gnustep/libobjc2#190 (comment).

Are there any options I’m missing, or is there maybe a CMake toolchain file somewhere I could use for this purpose?

The goal of this is to be able to build and debug LLVM/Clang using Visual Studio in order to add support for targeting MinGW in the Objective-C runtime support in Clang (gnustep/libobjc2#190). I tried building LLVM in Visual Studio after applying the MinGW patches, but this lead to various issues including Clang crashing for some compilations (maybe because of differences between MSVC and GCC, which I gather is used for building the MinGW Clang package?).

Any help would be appreciated. Thanks!

@lazka
Copy link
Member

lazka commented Mar 6, 2021

@mati865 might know

I'm not sure if this is possible...

@Amphaal
Copy link
Contributor

Amphaal commented Mar 6, 2021

Have a look at my CMake toolchain file for MinGW ABI cross-compilation for Archlinux, you might find some ideas to fix yours (https://github.com/Amphaal/rpgrpz/blob/master/cmake/toolchains/windows-ci.cmake)

I've noticed that CMAKE_EXE_LINKER_FLAGS_INIT and CMAKE_SHARED_LINKER_FLAGS_INIT are somewhat mandatory to change for initial CMake tests to succeed.

@mati865
Copy link
Collaborator

mati865 commented Mar 7, 2021

There should be no C:/msys64/usr/lib/libm.a in your link command.

Is libc++abi coming from official LLVM installer or MSYS2 package?
Our libc++abi is built with LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS=OFF since those are provided by libc++ in our builds.

To be compatible with GCC ABI you will have to pass -femulated-tls when using other Clang than our package.

@triplef
Copy link
Author

triplef commented Mar 8, 2021

Thanks so much everyone! @Amphaal’s toolchain file got me in the right direction – I think the trick was simply to use a toolchain file instead of specifying the options on the command line, because toolchain options are also passed through to try_compile().

Here’s the full toolchain file I ended up with:
clang-mingw.cmake.txt

Note that the sysroot path has to be a Windows-style path C:/msys64/mingw64 for Windows-Clang. I didn’t need any of the search paths, I’m guessing the CMAKE_SYSROOT already takes care of most of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants