# Distributing Fortran projects for Windows / MacOS

**URL:** https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760
**Category:** Help
**Created:** [February 27, 2021, 2:50pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760 "2021-02-27T14:50:47Z")
**Posts on this page:** 11
**Page:** 1

<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: [February 27, 2021, 2:50pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/1 "2021-02-27T14:50:47Z")

</div>

Reliable software distribution is one of the major issues I faced when starting my open source projects. Especially proprietary operating systems like Windows and OSX have always been hard to support, because I don’t have those available in my local development environment. Yet I get plenty of requests for Windows and OSX versions.

I’m currently relying mostly on conda-forge to distribute Fortran programs, which does a great job to reliably create packages for Linux (x86\_64, ppc64le and aarch64) and OSX (x86\_64) based on GFortran 9 (there is also aarch64 for OSX available now, but I haven’t tried this toolchain yet).

I also explored homebrew for OSX a while ago, which always has been a dead-end for modern Fortran because of their GFortran 4.9 version requirement to build the bottled packages. Packaging for OSX is particular difficult because you cannot statically link binaries like on Linux, distribution outside of a package manager therefore always seemed unfeasible for me.

Distribution for Windows has been an issue so far, conda-forge offers either classic flang 5 with LLVM or GFortran 5 with MinGW, which left me stuck with a similar issue I faced with homebrew: modern Fortran projects don’t compile with this setup.

What is your experience with packaging Fortran projects? Have you found a good solution for creating distributions for Windows?

---

<div class="post-metadata">

### Author: ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)
#### Post date: [February 27, 2021, 4:19pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/2 "2021-02-27T16:19:01Z")

</div>

There are two distinctions:

- Cross-platform binary package manager: I also use `Conda` . To fix Windows, cannot you simply compile your Conda packages at `conda-forge` using a more modern compiler?

- Cross-platform source package manager: we are hoping `fpm` will fill this role for Fortran. There are other source package managers such as Spack, which is planning to add Windows support.

---

<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: [February 27, 2021, 4:44pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/3 "2021-02-27T16:44:17Z")

</div>

I’m looking for a binary package manager, having users compile on their system opens a whole new can of worms 😉. Providing source code distributions for developers works perfectly fine with fpm or meson so far.

> [@certik](#):
>
> To fix Windows, cannot you simply compile your Conda packages at `conda-forge` using a more modern compiler?

I don’t think they have newer compilers packaged. You can check the Fortran compilers available here:

- [M2W64 Gcc Fortran :: Anaconda.org](https://anaconda.org/conda-forge/m2w64-gcc-fortran)
- [Flang Win 64 :: Anaconda.org](https://anaconda.org/conda-forge/flang_win-64) (looks like flang 11 was packaged recently 🎉)

---

<div class="post-metadata">

### Author: ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)
#### Post date: [March 1, 2021, 7:53am UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/4 "2021-03-01T07:53:50Z")

</div>

I see. We should package the latest GFortran for Windows.

Btw, one of the goals of LFortran is to have a first class support on Windows and good interoperation with MSVC. But we are not there yet for production codes.

---

<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: [March 3, 2021, 4:50pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/5 "2021-03-03T16:50:09Z")

</div>

It seems like we are not yet there for reliably distributing Fortran software for Windows, are we? From my limited knowledge on Windows there seem to exist at least several other packaging ecosystems beside conda as well:

- [scoop](https://scoop.sh/)
- [msys2](https://www.msys2.org/)
- [cygwin](https://cygwin.com/)
- [chocolatey](https://chocolatey.org/)

But maybe my assumption that one is using a package manager on Windows is a naive one.

---

<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: [March 16, 2021, 12:19pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/6 "2021-03-16T12:19:36Z")

</div>

Let’s rephrase the question and concentrate on a concrete example:  
_How would one package `fpm` for MacOS or Windows to reach a large amount of users?_

---

<div class="post-metadata">

### Author: ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)
#### Post date: [March 16, 2021, 10:58pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/7 "2021-03-16T22:58:11Z")

</div>

I think the answer for MacOS is simple; Homebrew.

---

<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: [March 16, 2021, 11:12pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/8 "2021-03-16T23:12:08Z")

</div>

I did try using Linuxbrew for a while, I guess a Formula like this might be able to build `fpm`:

```ruby
class Fpm < Formula
  desc "Fortran Package Manager (fpm)"
  homepage "https://fpm.fortran-lang.org"
  url "https://github.com/fortran-lang/fpm/releases/download/v0.1.4/fpm-0.1.4.f90"
  sha256 "06c139b16cf871e06cd3ea3be93c1ddbb5a94e4546a0c64822d10dc87333ac0c"
  license "MIT"

  depends_on "gcc" # for gfortran
  fails_with :gcc => "4"
  fails_with :gcc => "5"
  fails_with :gcc => "6"
  fails_with :clang

  def install
    # ENV.fc is not defined and setting it up with ENV.fortran will yield default gfortran
    ENV["FC"] = ENV.cc.gsub /gcc/, "gfortran"
    system ENV["FC"], "fpm-0.1.4.f90", "-o", "fpm"
    bin.install "fpm"
  end

  test do
    system "#{bin}/fpm", "--version"
  end
end

```

Selecting a Fortran compiler other than GCC 4 required me a bit of hacking… not sure if this is still an issue in brew.

---

<div class="post-metadata">

### Author: ![lkedward](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/lkedward/32/72_2.png) [@lkedward](https://fortran-lang.discourse.group/u/lkedward)
#### Post date: [March 17, 2021, 12:40pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/9 "2021-03-17T12:40:05Z")

</div>

> [@awvwgk](#):
>
> I don’t think they have newer compilers packaged.

Is the intel fortran compiler a possible option for windows?

---

<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: [March 17, 2021, 1:11pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/10 "2021-03-17T13:11:24Z")

</div>

> [@lkedward](#):
>
> Is the intel fortran compiler a possible option for windows?

As far as I know the answer is not yet. There has been discussions on the conda-forge gitter channel regarding the oneAPI compilers with no clear outcome yet.

Anaconda seems to be using Intel Parallel Studio to build most of their Windows stack and I know of many communities that use Intel oneAPI already to build their packages for Windows, MacOS and Linux, but this doesn’t mean it is automatically working for open source community at conda-forge as well.

Related gitter thread: [https://gitter.im/conda-forge/conda-forge-compilers?at=5fd254cf91e8cb3e8cf24dfc](https://gitter.im/conda-forge/conda-forge-compilers?at=5fd254cf91e8cb3e8cf24dfc)

---

<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: [March 17, 2021, 7:08pm UTC](https://fortran-lang.discourse.group/t/distributing-fortran-projects-for-windows-macos/760/11 "2021-03-17T19:08:30Z")

</div>

For Windows distributing a MinGW packages might be the way to go.

The `PKGBUILD` would look somewhat like this:

```auto
_realname=fpm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.4
pkgrel=1
arch=('any')
pkgdesc="Fortran package manager (mingw-w64)"
url="https://github.com/fortran-lang/fpm"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc-fortran")
options=('strip')
license=('MIT')
source=(${_realname}-${pkgver}.f90::"https://github.com/fortran-lang/fpm/releases/download/v${pkgver}/${_realname}-${pkgver}.f90")
sha256sums=('06c139b16cf871e06cd3ea3be93c1ddbb5a94e4546a0c64822d10dc87333ac0c')
noextract=("${_realname}-${pkgver}.f90")

build() {
  cd "${srcdir}"
  local _build="build_${CARCH}"
  local _fc="${MINGW_PREFIX}/bin/gfortran"
  # Compiler flags need some tweaking
  local _fflags="-J ${_build}"

  mkdir -p "${_build}"
  ${_fc} ${_fflags} "fpm-${pkgver}.f90" -o "${_build}/fpm"
}

package() {
  cd "${srcdir}/build_${CARCH}"
  install -Dm755 fpm "${pkgdir}"${MINGW_PREFIX}/bin/fpm
}

```

One can build and install fpm using the following commands (`PKGBUILD` file is in the working directory):

```auto
MINGW_INSTALLS=mingw64 makepkg-mingw
pacman -U mingw-w64-x86_64-fpm-0.1.4-1-any.pkg.tar.zst

```
