# Building Flang?

**URL:** <https://fortran-lang.discourse.group/t/building-flang/10697>\
**Category:** Help\
**Created:** [February 6, 2026, 7:49am UTC](https://fortran-lang.discourse.group/t/building-flang/10697 "2026-02-06T07:49:45Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [February 6, 2026, 7:49am UTC](https://fortran-lang.discourse.group/t/building-flang/10697/1 "2026-02-06T07:49:45Z")

</div>

In another thread ([Please, No More Loops (Than Necessary): New Patterns in Fortran 2023](https://fortran-lang.discourse.group/t/please-no-more-loops-than-necessary-new-patterns-in-fortran-2023/10605)) @rousson suggested Flang as a possible compiler to experiment with offloading DO CONCURRENT loops to GPUs. I have tried to build it, following to my best intentions the instructions at [Building Flang · flang-compiler/flang Wiki · GitHub](https://github.com/flang-compiler/flang/wiki/Building-Flang), but I stumbled in the process:

- I first tried to build LLVM (the fork mentioned in the Wiki) on plain Windows. But at some point the “../..” notation got in the way, as I got the error message that “..” was not a known program or command.
- So, I switched to WSL and after a long CMake session (it took literally two hours to complete), I got the set of makefiles that ought to do the trick. Alas, that failed on a compile error:

```auto
[8%] Building CXX object lib/IR/CMakeFiles/LLVMCore.dir/CycleInfo.cpp.o
[8%] Building CXX object lib/IR/CMakeFiles/LLVMCore.dir/DIBuilder.cpp.o
/mnt/d/flang/LLVM/llvm/lib/IR/DIBuilder.cpp:753:29: error: no declaration matches ‘llvm::DIGlobalVariableExpression* llvm::DIBuilder::createGlobalVariableExpression(llvm::DIScope*, llvm::StringRef, llvm::StringRef, llvm::DIFile*, unsigned int, llvm::DIType*, bool, bool, llvm::DIExpression*, llvm::MDNode*, llvm::MDTuple*, llvm::DINode::DIFlags, uint32_t, llvm::DINodeArray)’
  753 | DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression(
      | ^ ~~~~~~~~

```

So, that ended that attempt.

I may have done something wrong, I guess, but can anybody suggest a solution?

(I will try to get the NVidia Fortran compiler to work in my set-up - again via WSL, as there is no WIndows version available as far as I can tell.)

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [February 6, 2026, 8:29am UTC](https://fortran-lang.discourse.group/t/building-flang/10697/2 "2026-02-06T08:29:48Z")

</div>

Installing the NVidia stuff turns out to be a multistep thing. I will have to muster time and patience …

---

<div class="post-metadata">

**Author:** ![apoorv01](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@apoorv01](https://fortran-lang.discourse.group/u/apoorv01)\
**Post date:** [February 6, 2026, 1:27pm UTC](https://fortran-lang.discourse.group/t/building-flang/10697/3 "2026-02-06T13:27:15Z")

</div>

Hi Arjen

Hope this link will help you get Flang-21 for windows. I have used Flang only on linux so cannot comment of usefulness for Windows

> **[Releases · llvm/llvm-project](https://github.com/llvm/llvm-project/releases)**
>
> The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. - llvm/llvm-project

Apurva

---

<div class="post-metadata">

**Author:** ![zedthree](https://avatars.discourse-cdn.com/v4/letter/z/f4b2a3/32.png) [@zedthree](https://fortran-lang.discourse.group/u/zedthree)\
**Post date:** [February 6, 2026, 3:37pm UTC](https://fortran-lang.discourse.group/t/building-flang/10697/4 "2026-02-06T15:37:24Z")

</div>

I think you might have fallen for the “classic flang” vs “new/LLVM flang” pitfall. If you weren’t aware, “classic flang” is the old PGI/NVidia compiler frontend (`pgfortran`) open-sourced and ported to use LLVM as the backend, and is developed separately from LLVM. “New flang” or “LLVM flang” is developed as part of the LLVM project, and is much more integrated into LLVM. They have been saying for several years that “classic flang” will somehow merge into “new flang”.

[Here are the instructions for building new/LLVM flang with support for GPUs](https://flang.llvm.org/docs/GettingStarted.html#building-flang-rt-for-accelerators), you don’t need to use a fork of LLVM for that, you can use the latest release that @apoorv01 linked to.

In my experience, expect it to take 2-4 hours to compile (and take a lot of RAM!)

---

<div class="post-metadata">

**Author:** ![tmj](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@tmj](https://fortran-lang.discourse.group/u/tmj)\
**Post date:** [February 6, 2026, 4:00pm UTC](https://fortran-lang.discourse.group/t/building-flang/10697/5 "2026-02-06T16:00:46Z")

</div>

> [@zedthree](#):
>
> 2-4 hours to compile

(Obviously depending on hardware, but) the Flang build times can be dropped dramatically with shared libs and optimized tablegen. Here’s what I use for building a (nominally usable for AMD GPUs with OpenMP) “main” version of Flang from source on Linux, which includes support for LIT and llvm-test-suite testing. It’s about 25 minutes for a clean build on my AMD Ryzen desktop.  
`cmake -G “Ninja” `  
` -DBUILD_SHARED_LIBS=On `  
` -DCMAKE_BUILD_TYPE=RelWithDebInfo `  
` -DCMAKE_C_COMPILER=/usr/bin/clang `  
` -DCMAKE_CXX_COMPILER=/usr/bin/clang++ `  
` -DCMAKE_C_FLAGS=-march=native `  
` -DCMAKE_CXX_FLAGS=-march=native `  
` -DCMAKE_EXPORT_COMPILE_COMMANDS=ON `  
` -DCOMPILER_RT_BUILD_XRAY=ON `  
` -DFLANG_ENABLE_WERROR=ON `  
` -DFLANG_RUNTIME_F128_MATH_LIB=libquadmath `  
` -DFLANG_RT_INCLUDE_TESTS=On `  
` -DLLVM_BUILD_DOCS=OFF `  
` -DLLVM_BUILD_EXAMPLES=OFF `  
` -DLLVM_BUILD_TESTS=On `  
` -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-pc-linux-gnu `  
` -DLLVM_ENABLE_ASSERTIONS=ON `  
` -DLLVM_ENABLE_DOXYGEN=OFF `  
` -DLLVM_ENABLE_IDE=ON `  
` -DLLVM_ENABLE_PROJECTS=“clang;lld;mlir;flang;clang-tools-extra” `  
` -DLLVM_ENABLE_RUNTIMES=“compiler-rt;openmp;libunwind” `  
` -DLLVM_ENABLE_SPHINX=OFF `  
` -DLLVM_INCLUDE_TESTS=On `  
` -DLLVM_OPTIMIZED_TABLEGEN=ON `  
` -DLLVM_LIT_ARGS=“-v --xunit-xml-output test-results.xml” `  
` -DLLVM_PARALLEL_LINK_JOBS=12 `  
` -DLLVM_TARGETS_TO_BUILD=“X86;AMDGPU” `  
` -DLLVM_USE_LINKER=lld `  
` -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=“compiler-rt;libc;libcxx;libcxxabi;flang-rt;openmp” `  
` -DRUNTIMES_amdgcn-amd-amdhsa_FLANG_RT_LIBC_PROVIDER=“llvm” `  
` -DRUNTIMES_amdgcn-amd-amdhsa_FLANG_RT_LIBCXX_PROVIDER=“llvm” `  
` -DRUNTIMES_amdgcn-amd-amdhsa_CACHE_FILES=“${LLCM_SRC_DIR}/build/../libcxx/cmake/caches/AMDGPU.cmake” `  
`../llvm`

---

<div class="post-metadata">

**Author:** ![rwmsu](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rwmsu](https://fortran-lang.discourse.group/u/rwmsu)\
**Post date:** [February 6, 2026, 4:55pm UTC](https://fortran-lang.discourse.group/t/building-flang/10697/6 "2026-02-06T16:55:22Z")

</div>

I think I remember someone mentioned here of installing using conda and/or homebrew. Not sure which version. I recently found after updating to the latest Linux Mint (Ubuntu 24.04 lts based) that llvm-20 (including new flang 20) is available directly from the standard repository. I don’t know if it includes GPU offloading though (probably doesn’t). Don’t know which version of Linux you are using under WSL but you might try a very recent Ubuntu or similar distribution. I think that LFortran 0.39 is also available.

---

<div class="post-metadata">

**Author:** ![kamelstekspizza](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kamelstekspizza/32/5132_2.png) [@kamelstekspizza](https://fortran-lang.discourse.group/u/kamelstekspizza)\
**Post date:** [February 6, 2026, 5:53pm UTC](https://fortran-lang.discourse.group/t/building-flang/10697/7 "2026-02-06T17:53:18Z")

</div>

Homebrew currently has flang 21.1.8 available as the latest stable version. According to [https://llvm.org/](https://llvm.org/), LLVM 22 should be released in the coming weeks (it’s currently in the release candidate phase).

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [February 7, 2026, 10:46am UTC](https://fortran-lang.discourse.group/t/building-flang/10697/8 "2026-02-07T10:46:03Z")

</div>

Thanks for this information and these links. It is indeed the rather confusing distinction between “classic Flang” and “new Flang” that I have fallen victim to. Let me just start again and see how that works out.

---

<div class="post-metadata">

**Author:** ![HugoMVale](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@HugoMVale](https://fortran-lang.discourse.group/u/HugoMVale)\
**Post date:** [February 7, 2026, 11:03am UTC](https://fortran-lang.discourse.group/t/building-flang/10697/9 "2026-02-07T11:03:28Z")

</div>

Why build it?  
With conda / mamba, the installation is effortless on linux and windows.

[flang - conda-forge | Anaconda.org](https://anaconda.org/channels/conda-forge/packages/flang/overview)

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [February 7, 2026, 11:32am UTC](https://fortran-lang.discourse.group/t/building-flang/10697/10 "2026-02-07T11:32:42Z")

</div>

Ah, that did the trick for installing flang, but if I try to build a (simple) program then flang complains about the run-time library flang\_rt.runtime.static.lib:

```auto
flang hello.f90
LINK : fatal error LNK1104: cannot open file 'flang_rt.runtime.static.lib'
flang: error: linker command failed with exit code 1104 (use -v to see invocation)

```

There are reportedly packages “flang\_rt-win-64” but these fail to be installed.

Also the installation as I have it now (I simply followed the instructions) lacks an omp\_lib module.

---

<div class="post-metadata">

**Author:** ![HugoMVale](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@HugoMVale](https://fortran-lang.discourse.group/u/HugoMVale)\
**Post date:** [February 7, 2026, 11:54am UTC](https://fortran-lang.discourse.group/t/building-flang/10697/11 "2026-02-07T11:54:42Z")

</div>

You need to install the omp module :  
[llvm-openmp - conda-forge | Anaconda.org](https://anaconda.org/channels/conda-forge/packages/llvm-openmp/overview)

and the runtime as well:

- linux/WLS, with certainty: [libflang-rt - conda-forge | Anaconda.org](https://anaconda.org/channels/conda-forge/packages/libflang-rt/overview)
- Windows, probably: [flang-rt\_win-64](https://anaconda.org/conda-forge/flang-rt_win-64)

Locally, I have only used it in linux. But in github actions, this runs on windows as well.  
[bump to 3.0.3 · HugoMVale/odrpack95@f5a0d49](https://github.com/HugoMVale/odrpack95/actions/runs/21414641079/job/61660202588)

You might also try checking if the problem is that the lib file does not exist or if it simply cannot be found by the linker. In the latter case, just add the respective folder to LIB.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [February 7, 2026, 6:43pm UTC](https://fortran-lang.discourse.group/t/building-flang/10697/12 "2026-02-07T18:43:32Z")

</div>

With these installed it works, thanks again.

Just a few remarks:

- There is no omp\_lib module, instead I need to include the header file
- The option -fdo-concurrent-to-openmp=device gives the error message that this has not been implemented yet.

So instead I am trying with plain OpenMP. That seems to keep the CPUs very busy.

Anyway, the first step has been set 😊

---

<div class="post-metadata">

**Author:** ![zaikunzhang](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zaikunzhang/32/785_2.png) [@zaikunzhang](https://fortran-lang.discourse.group/u/zaikunzhang)\
**Post date:** [February 8, 2026, 6:02am UTC](https://fortran-lang.discourse.group/t/building-flang/10697/13 "2026-02-08T06:02:00Z")

</div>

If you are fine with pre-built binaries, see

> <https://github.com/equipez/github_actions_scripts/blob/main/install_llvm>

N.B.: I use this script to install LLVM (especially flang) on GitHub-hosted runners (virtual machines). If you intend to use it on your own machine, check the code first.

---

<div class="post-metadata">

**Author:** ![hkvzjal](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hkvzjal/32/3055_2.png) [@hkvzjal](https://fortran-lang.discourse.group/u/hkvzjal)\
**Post date:** [February 8, 2026, 12:33pm UTC](https://fortran-lang.discourse.group/t/building-flang/10697/14 "2026-02-08T12:33:43Z")

</div>

You remotivated me to retry flang after so many fail attempts to get it actually working on a conda env on windows. While I couldn’t build stdlib with it because there are some missing features in the compiler, it did “work” in the sense of installing and building and reporting warnings and errors.

I’ll leave a few tips of what I had to do for reference:

Isolate the LLVM environment

```auto
conda create -n llvm

```

Install the required compiler, libraries and runtimes

```auto
conda activate llvm
conda install conda-forge::flang llvm-openmp flang-rt_win-64 vs2022_win-64  

```

For CMake, I hit a very tiny but annoying issue that took me some iterations to find, one has to declare `clang-cl` (not `clang`) as the C compiler if building outside a unix-like terminal for a MVSC-like behavior instead of GNU:

```auto
-DCMAKE_Fortran_COMPILER=flang 
-DCMAKE_C_COMPILER=clang-cl

```

---

<div class="post-metadata">

**Author:** ![HugoMVale](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@HugoMVale](https://fortran-lang.discourse.group/u/HugoMVale)\
**Post date:** [February 8, 2026, 8:47pm UTC](https://fortran-lang.discourse.group/t/building-flang/10697/15 "2026-02-08T20:47:44Z")

</div>

Interesting! I recently had to learn how to use flang exactly because it’s the default Fortran compiler in conda-forge for windows. It took me quite a lot of iterations to get it working, even though the result is quite simple.

If anyone is facing a similar challenge, just copy the approach used here.

[HugoMVale/odrpack-feedstock: A conda-smithy repository for odrpack.](https://github.com/HugoMVale/odrpack-feedstock)

---

<div class="post-metadata">

**Author:** ![rouson](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@rouson](https://fortran-lang.discourse.group/u/rouson)\
**Post date:** [February 10, 2026, 6:14am UTC](https://fortran-lang.discourse.group/t/building-flang/10697/16 "2026-02-10T06:14:44Z")

</div>

@Arjen my apologies for any confusion. The ability for LLVM `flang` to offload `do concurrent` is experimental and under development. The work is far enough along that I suspect some cases can be offloaded if the compiler is built with OpenMP support and if the Fortran code is built with the right combination flags is passed, but even in those cases, it might require building a downstream fork of llvm-project. I occasionally meet with a compiler engineer who is working on `flang`’s `do concurrent` offloading support, but I haven’t tried it yet because I know it can’t offload the code that I most care about. As soon as `flang` can offload my code, I’ll test it and report back.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [February 10, 2026, 8:00am UTC](https://fortran-lang.discourse.group/t/building-flang/10697/17 "2026-02-10T08:00:27Z")

</div>

Most of the confusion was getting Flang to work on my machine 🙂 I quite understand that a new compiler like Flang does not support everything yet. It was more of a surprise to see that compiling with OpenMP caused the CPUs to grind heavily on my sample program, whereas the directives did include offloading. It seems these parts were ignored. But those are very preliminary observations.

---

<div class="post-metadata">

**Author:** ![BFelsher](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@BFelsher](https://fortran-lang.discourse.group/u/BFelsher)\
**Post date:** [April 6, 2026, 9:02pm UTC](https://fortran-lang.discourse.group/t/building-flang/10697/18 "2026-04-06T21:02:01Z")

</div>

choco install llvm
