1

I have some modern C++ sources (C++17, say) and I have no problem compiling complex source base on Linux for Linux 32/64, and on Windows for Windows 32/64 using mingw-w64 (from msys2).

Now I want to cross compile for Windows on Linux, to avoid using a virtual machine just to compile.

So I tried installing mingw-w64 from the Ubuntu repository, but it was compiled with --enable-threads=win32, which is not compatible with std::mutex, for instance, from C++11.

I wasn't able to compile mingw-w64-v7 from source (it only compiles a bunch of libraries and not the compiler itself), I wasn't able to get a single binary already compiled for Linux 64bits either.

What is the way to go to setup a cross compiling toolchain that compiles modern C++ from Linux to get Windows 32 and 64 bits executables?

t.niese
  • 39,256
  • 9
  • 74
  • 101
Leandro
  • 195
  • 3
  • 11
  • Visual Studio ? – Paul Sanders May 04 '20 at 18:24
  • @DevSolar MinGW exists for Linux hosts as well, targeting Windows. – Some programmer dude May 04 '20 at 18:27
  • Does this answer your question? [How to compile for Windows on Linux with gcc/g++?](https://stackoverflow.com/questions/2033997/how-to-compile-for-windows-on-linux-with-gcc-g) – Hack06 May 04 '20 at 18:29
  • @Hack06: no, as I said in the question, the first thing I tried was mingw, but it doesn't support a full modern c++, as it uses the win32 thread approach, when std::mutex needs pthread (--enable-threads=posix). What I need is a binary mingw-w64 with pthread, already compiled or instructions (reasonably recent) on how to compile it from sources, or any other method to get proper cross compilation. – Leandro May 05 '20 at 01:55
  • 1
    @PaulSanders: no, Visual Studio, as far as I know, doesn't run on Linux. I already have figured out how to compile modern C++ from Windows using mingw-w64, what I need is to do it from Linux. – Leandro May 05 '20 at 01:56
  • Sorry, I missed that requirement. Perhaps you can run your Windows tools in a VM. – Paul Sanders May 05 '20 at 10:57
  • 2
    @PaulSanders: I also said I already do that, and that's what I want to avoid. – Leandro May 05 '20 at 11:21
  • 1
    My Ubuntu 18.04 has a POSIX-threaded mingw-w64 toolchain as well. Try `update-alternatives --list x86_64-w64-mingw32-g++`. – David Macek May 05 '20 at 17:14
  • @DavidMacek: right! I didn't know that, perfect, that solves the problem. – Leandro May 05 '20 at 18:06

1 Answers1

2

My Ubuntu 18.04 has a POSIX-threaded mingw-w64 toolchain as well. Try update-alternatives --list x86_64-w64-mingw32-g++.

David Macek
  • 868
  • 4
  • 10