[llvm-dev] Guidance on cross compiling LLVM with mingw-w64 and cmake

Chris Bieneman via llvm-dev llvm-dev at lists.llvm.org
Thu Feb 11 10:27:04 PST 2016

Sadly you are way out in uncharted territory. I’m unaware of anyone using gcc to cross-compile LLVM. At Apple we extensively cross-compile, but we use clang as our host compiler.

I’m not sure why you’re seeing the native CMake picking up your cross-compiler instead of your host compiler. Our CMake scripts don’t pass through he compiler from one configuration to the next. I’m guessing the “native” CMake is probably picking up the cross-compiler from the environment somehow (maybe the CC and CXX envar).

You can probably work around the issue by configuring a host LLVM directory and passing that directory into your cross-configured CMake invocation with the LLVM_NATIVE_BUILD option.

Because you are off in uncharted territory I expect you’re mostly going to be on your own for debugging and diagnosing. I can answer specific questions, but I haven’t used a gcc toolchain for cross-compiling since the early days of the PS3 (and I’ve pretty much blocked that out of my memory).


> On Feb 10, 2016, at 11:43 PM, Tony Kelman <tony at kelman.net> wrote:
>> The problem you are hitting is caused by setting CMAKE_SYSTEM_NAME.
>> When you set that CMake sets a variable CMAKE_CROSS_COMPILING. That
>> variable should only be set when your host OS doesn't match your target
>> OS. Since LLVM needs to build host-capable tools there is some goop to
>> call out and configure a new CMake build directory to target the host.
> Right. My build OS doesn't match my target OS, my build is Linux or Cygwin,
> and the target is Win32. So setting CMAKE_CROSS_COMPILING is correct.
> It's the "goop" that needs some work to get back to parity with the
> functionality that was working on autotools. Sorry I didn't try running
> this configuration earlier on in the autotools-deprecation process.
> The new CMake build directory for the native tools needs to not use the
> same settings for compiler names as the parent cross-compile build.
> Any ideas how to accomplish this? I'm happy to help test out patches
> and dig into cmake docs as necessary to get this working. If this would
> be more appropriate to work through in an issue than on the mailing
> list, do say so.
> -Tony

More information about the llvm-dev mailing list