# Where is the mingw cross-compiler?

**URL:** <https://fortran-lang.discourse.group/t/where-is-the-mingw-cross-compiler/3810>\
**Category:** Help\
**Created:** [June 20, 2022, 10:43pm UTC](https://fortran-lang.discourse.group/t/where-is-the-mingw-cross-compiler/3810 "2022-06-20T22:43:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![feenberg](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@feenberg](https://fortran-lang.discourse.group/u/feenberg)\
**Post date:** [June 20, 2022, 10:43pm UTC](https://fortran-lang.discourse.group/t/where-is-the-mingw-cross-compiler/3810/1 "2022-06-20T22:43:20Z")

</div>

I have been using the Mingw32 cross compiler in Linux for creating Windows executables for many years, but lately it doesn’t seem to be in any of the usual RPM style repositories.

**yum search mingw**

doesn’t turn anything up, nor does **dnf**. There is a page:

https://fedoraproject.org/wiki/MinGW

that seems to offer the software, but no link and no name is given. I don’t need the most recent version - something from 2008 would be fine. 32 or 64 bit is fine. gcc or LLVM are fine. Any compiler that will run in Centos and produce Windows exe files from standard f77 is fine. I would like to avoid a virtual machine or container, though.

I did find a version for FreeBSD in the the ports collection, and I was able to build that from source, and it does work. But I am still looking for a Linux version as the rest of the project is mostly Linux based.

Daniel Feenberg  
NBER

---

<div class="post-metadata">

**Author:** ![nbehrnd](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@nbehrnd](https://fortran-lang.discourse.group/u/nbehrnd)\
**Post date:** [June 21, 2022, 6:53pm UTC](https://fortran-lang.discourse.group/t/where-is-the-mingw-cross-compiler/3810/2 "2022-06-21T18:53:41Z")

</div>

I have no experience with MinGW, nor Fedora. On the other hand – since `mingw` doesn’t show up in Debian’s package manager `synaptic` either – typing just `mingw` in Debian’s [package tracker](https://tracker.debian.org/) points to multiple entries, including [binutils-mingw-w64](https://tracker.debian.org/pkg/binutils-mingw-w64) with a time stamp of 2021-11-02 for Debian’s branch testing (12/bookworm) (more [details](https://packages.debian.org/unstable/binutils-mingw-w64) here eventually lead to download a .deb package).

Like there is benefit to complement Windows by a WSL or a .true. Linux installation, the cohabitation of two (or more) different Linuxes on one machine requires some rules but then equally works fine. Possibly equally here.

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [June 21, 2022, 6:59pm UTC](https://fortran-lang.discourse.group/t/where-is-the-mingw-cross-compiler/3810/3 "2022-06-21T18:59:02Z")

</div>

You can try to search in [https://repology.org/](https://repology.org/) for the MinGW cross toolchain, Fedora is for sure included in the repology database. Note that the naming of the cross-compiler is probably very inconsistent across distributions.

---

<div class="post-metadata">

**Author:** ![feenberg](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@feenberg](https://fortran-lang.discourse.group/u/feenberg)\
**Post date:** [June 21, 2022, 7:59pm UTC](https://fortran-lang.discourse.group/t/where-is-the-mingw-cross-compiler/3810/4 "2022-06-21T19:59:55Z")

</div>

The string “mingw” is used in the names of two separate projects. One is Windows compiler forked from gcc, another is a cross compiler for Linux or Freebsd that compiles to Windows executables, also forked from gcc. As far as I can tell, everything in Repology is either the Windows compiler, or it’s libraries, none are for the cross-compiler. I can’t be sure of that, since none of the packages listed have any sort of descriptive label. “binutils” is identified on the gcc site as a collection of routines other than the compiler itself. There are a couple of links to packages call “mingw-gcc-\*” which would be where the compiler should be, but they are very small - a few hundred lines, so they can’t be a cross-compiler.

It is a pity that a significant development effort for something so potentially valuable seems so hard to find. It is out there somewhere.

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [June 21, 2022, 8:14pm UTC](https://fortran-lang.discourse.group/t/where-is-the-mingw-cross-compiler/3810/5 "2022-06-21T20:14:39Z")

</div>

For Arch Linux there is [Arch Linux - mingw-w64-gcc 12.1.0-1 (x86\_64)](https://archlinux.org/packages/community/x86_64/mingw-w64-gcc/), which is the actual cross-compiler.

Searching repology for [mingw in the Fedora repositories](https://repology.org/projects/?search=mingw&maintainer=&category=&inrepo=fedora_36&notinrepo=&repos=&families=&repos_newest=&families_newest=) returns its C runtime: [Overview - rpms/mingw-crt - src.fedoraproject.org](https://src.fedoraproject.org/rpms/mingw-crt). By analogy one could guess that there is probably a compiler as well: [Overview - rpms/mingw-gcc - src.fedoraproject.org](https://src.fedoraproject.org/rpms/mingw-gcc).

Since it doesn’t show up in the repo, it might have been dropped from the Fedora distribution. You can always reach out to the Fedora project and volunteer as new maintainer for the MinGW cross-compiler, checkout [Fedora Packaging Guidelines :: Fedora Docs](https://docs.fedoraproject.org/en-US/packaging-guidelines/) for more details on how to get involved with the Fedora project (I haven’t packaged for Fedora yet, but I know at least one Fedora package maintainer).

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [May 7, 2023, 10:24pm UTC](https://fortran-lang.discourse.group/t/where-is-the-mingw-cross-compiler/3810/6 "2023-05-07T22:24:16Z")

</div>

What worked for me on Ubuntu 20.04 (Focal) was:

```plaintext
$ sudo apt-get install mingw-w64
$ sudo apt-get install gfortran-mingw-w64-x86-64
$ sudo apt-get install wine # to run the programs

```

This required roughly 2 GB of memory.

Next I created the following [CMake toolchain file](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html):

```auto
# mingw.cmake

# the name of the target operating system
set(CMAKE_SYSTEM_NAME Windows)

# which compilers to use for C and C++
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_Fortran_COMPILER x86_64-w64-mingw32-gfortran)

# where is the target environment located
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)

# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

```

The toolchain file can be referenced in the build configuration step:

```auto
~fortran/win/build$ cmake -DCMAKE_TOOLCHAIN_FILE=../mingw.cmake ..

```

Otherwise you just use CMake as usual:

```plaintext
cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR)

project(test VERSION 0.1.0 LANGUAGES CXX C Fortran)

if(CMAKE_SYSTEM MATCHES Windows)
   message(STATUS "Target system is Windows")
endif()

add_executable(main main.cpp)

add_executable(main-f90 main.f90)
if(CMAKE_CROSSCOMPILING)
    target_link_libraries(main-f90 PUBLIC "-static")
endif()

```

The main Fortran program was:

```auto
program main
use iso_fortran_env
print '(4a)', 'This file was compiled by ', &
              compiler_version(), ' using the options ', &
              compiler_options()
end program

```

Here is the output:

```plaintext
:~/fortran/win/build$ make main-f90
Scanning dependencies of target main-f90
[50%] Building Fortran object CMakeFiles/main-f90.dir/main.f90.o
[100%] Linking Fortran executable main-f90.exe
[100%] Built target main-f90
~/fortran/win/build$ wine ./main-f90.exe
This file was compiled by GCC version 9.3-win32 20200320 using the options -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/main-f90.dir/main.f90.o

```

I was quite surprised by how easy cross-compiling was. It’s a great showcase of the work that goes into MinGW, GCC, and CMake.

I wonder if it’s possible to develop QuickWin (Intel) or AppGraphics (Approximatrix, cc @jeff) apps this way?

---

<div class="post-metadata">

**Author:** ![jeff](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jeff/32/7201_2.png) [@jeff](https://fortran-lang.discourse.group/u/jeff)\
**Post date:** [August 15, 2023, 10:40am UTC](https://fortran-lang.discourse.group/t/where-is-the-mingw-cross-compiler/3810/7 "2023-08-15T10:40:20Z")

</div>

> [@ivanpribec](#):
>
> I wonder if it’s possible to develop QuickWin (Intel) or AppGraphics (Approximatrix, cc @jeff) apps this way?

It should work fine if one wanted to use the AppGraphics library. It looks like the _gfortran-mingw-w64-x86-64_ package does pull in the _mingw-w64-x86-64-dev_ package, which contains all the Win32 development libraries for linking.

The only catch might be that we only distribute a _.mod_ interface rather than the source for the module, so the compiler would have to be compatible. However, I don’t think GNU Fortran has changed _.mod_ files since maybe GNU Fortran 9 or so (used to be a perpetual issue)…
