Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I invoke the MinGW cross-compiler on Linux?

I have a project that I want to cross-compile for Windows. I have the appropriate Makefile and everything works with g++. I've run

$ apt install mingw-w64 

and downloaded 500 MB of packages, but I cannot find out how to actually run it. There is no mingw executable, so how do I actually compile with it?

like image 715
Martin Melka Avatar asked Apr 13 '13 10:04

Martin Melka


People also ask

How do you cross compile in MinGW?

used to compile your code for another system. Assuming you want to compile C++ code for a 64-bit system, you'll need to use /usr/bin/x86_64-w64-mingw32-g++-win32 . You can use the CXX environment variable to tell most Makefiles to use that compiler to compile code.

Can MinGW run on Linux?

MinGW (Minimalist GNU for Windows) is a free and open source software development environment to create Windows applications. It is licensed under the GNU General Public License. MinGW includes a simplified port of the GNU Compiler Collection (GCC), a compiler system for Linux.


1 Answers

If you look at the file lists on the Ubuntu package webserver for mingw-w64's constituent packages:

  • gcc-mingw-w64-x86-64
  • g++-mingw-w64-x86-64
  • binutils-mingw-w64-x86-64
  • mingw-w64-x86-64-dev
  • gcc-mingw-w64-i686
  • g++-mingw-w64-i686
  • binutils-mingw-w64-i686
  • mingw-w64-i686-dev

You can see that mingw-w64 provides a toolchain, i.e. a set of alternative tools (compiler, linker, headers, etc.) used to compile your code for another system.

Assuming you want to compile C++ code for a 64-bit system, you'll need to use /usr/bin/x86_64-w64-mingw32-g++-win32. You can use the CXX environment variable to tell most Makefiles to use that compiler to compile code.

like image 108
gipi Avatar answered Sep 21 '22 01:09

gipi