# LFortran looking for some help from a Windows user

**URL:** <https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737>\
**Category:** Uncategorized\
**Created:** [August 22, 2021, 7:31pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737 "2021-08-22T19:31:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsnyder](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hsnyder/32/747_2.png) [@hsnyder](https://fortran-lang.discourse.group/u/hsnyder)\
**Post date:** [August 22, 2021, 7:31pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/1 "2021-08-22T19:31:49Z")

</div>

Hi everyone,

Nobody currently working on LFortran actually uses Windows, which is causing us to struggle with getting it to link executables properly on that platform. If there’s anybody on this forum who is experienced with doing Fortran development on Windows and who might be willing to advise us on this?

We aren’t writing our own linker or anything terribly difficult like that - we just need to get LFortran to correctly invoke the platform linker to turn object files into executables.

CC: @certik

---

<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:** [August 22, 2021, 7:38pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/2 "2021-08-22T19:38:15Z")

</div>

Here is the exact issue:

- [Getting LFortran to link executables on Windows (#537) · Issues · lfortran / lfortran · GitLab](https://gitlab.com/lfortran/lfortran/-/issues/537)

It’s almost there, but not quite. Update: this issue is now fixed. I am very happy about that, LFortran can now create standalone executables on Windows using the usual:

```auto
lfortran -c examples/expr2.f90 -o expr2.o
lfortran -o expr2 expr2.o
./expr2

```

And it works. (Underneath it uses LLVM to generate object files and then it calls the Microsoft `link` linker to do the final linking.)

The main remaining task is to get cmake to work with LFortran, see this issue:

- [cmake doesn't work with LFortran on Windows (#536) · Issues · lfortran / lfortran · GitLab](https://gitlab.com/lfortran/lfortran/-/issues/536)

I don’t have a Windows machine, so I only debug it at the CI, which has about 10 min iterations, so it takes a long time. If somebody here uses Windows and has time to help, that would be very helpful. I can help with any LFortran’s internals, just need somebody to try to get it to link.

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [August 23, 2021, 12:36am UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/3 "2021-08-23T00:36:17Z")

</div>

I use Windows but am not familiar with cmake. If you want me to take a look, I’ll need instructions on what is needed to show the problem.

As for your first problem, Windows compilers typically add linker default library directives to the object file, that name the runtime libraries to link against. If you use the command:  
`dumpbin -directives foo.obj`  
(this assumes you have the MSVC tools in your environment) it will show you the directives in `foo.obj`. Try this on an ifort-compiled object to see. This has the advantage of not requiring the user to name all of the libraries needed. It has the disadvantage of there possibly being a conflict between sets of libraries requested by two or more objects/libraries.

On Linux, compiler drivers (ifort, gfortran, etc.) invisibly add the desired libraries to the command spawned to do the link.

---

<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:** [August 23, 2021, 2:19am UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/4 "2021-08-23T02:19:39Z")

</div>

Thanks @sblionel. It looks like we managed to fix the first problem, LFortran can now link on Windows using the MSVC’s `link` tool, and it links properly, including the LFortran’s runtime library. Thanks for the `dumpbin` tip. I’ll play with it to get a better understanding. Yes on Linux and macOS things work fine.

Regarding cmake — it seems CMake has some issues recognizing LFortran, the error comes from the internals of CMake and I don’t have any instructions to try, as I already tried the obvious workarounds. I’ll try to ask at some cmake forums, maybe somebody can help there.

---

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [August 23, 2021, 3:29am UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/5 "2021-08-23T03:29:21Z")

</div>

> [@certik](#):
>
> … The main remaining task is to get cmake to work with LFortran …

On Windows, since you’re currently using MSVC tool sets, can you consider `NMAKE`? NMAKE is a simpler make utility that works reasonably well with Microsoft toolchain and it can get you going with ironing out LFortran dependencies on the Windows OS until you have `fpm` working to your satisfaction with LFortran:

> **[NMAKE Reference](https://learn.microsoft.com/en-us/cpp/build/reference/nmake-reference?view=msvc-160)**
>
> Learn more about: NMAKE Reference

---

<div class="post-metadata">

**Author:** ![hsnyder](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hsnyder/32/747_2.png) [@hsnyder](https://fortran-lang.discourse.group/u/hsnyder)\
**Post date:** [August 23, 2021, 5:01am UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/6 "2021-08-23T05:01:12Z")

</div>

To clarify, the issue isn’t getting CMake to work in _building_ LFortran on Windows, rather it’s getting CMake to work properly with LFortran as the chosen compiler for a user’s project. So while we could advise people, “just use nmake”, it’s probably best if we can get this resolved so that someone can download an existing CMake fortran project, and compile it with LFortran.

As an aside, I was under the impression that CMake generated platform-specific makefiles (though I’m not a CMake expert by any stretch of the imagination - my experience with CMake has been uniformly unsavoury). On windows, shouldn’t that be an nmake file? My experience using CMake on Linux and FreeBSD has been that the workflow is: invoke CMake, which generates a makefile → invoke make to build the executable.

---

<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:** [August 23, 2021, 5:18am UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/7 "2021-08-23T05:18:06Z")

</div>

> [@hsnyder](#):
>
> On windows, shouldn’t that be an nmake file?

Yes. Or ninja.

---

<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:** [August 23, 2021, 6:28am UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/8 "2021-08-23T06:28:40Z")

</div>

CMake creates very specific makefiles (down to the exact location of the various programs that are required to build the program, like your compiler and linker), but it does so based on fairly generic configuration files. My experience with CMake is not as bad as some people’s, but then I have most often been a user of CMake-based projects and I have tried to develop with other build systems, which was not a pleasant experience either 🙂.

Crucial here is that CMake understands the LFortran compiler - you need a configuration file that allows it to generate the right commands.

---

<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:** [August 23, 2021, 2:23pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/9 "2021-08-23T14:23:54Z")

</div>

> [@Arjen](#):
>
> Crucial here is that CMake understands the LFortran compiler - you need a configuration file that allows it to generate the right commands.

On Linux and macOS, this is how CMake recognizes LFortran:

```auto
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The Fortran compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Cray Programming Environment (unknown version) Fortran
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /Users/certik/bin/lfortran - skipped
-- Checking whether /Users/certik/bin/lfortran supports Fortran 90
-- Checking whether /Users/certik/bin/lfortran supports Fortran 90 - yes

```

It thinks it is a Cray compiler. 🙂 But it works, since LFortran uses the usual command line options. I guess on Windows it fails somehow.

---

<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:** [August 23, 2021, 2:54pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/10 "2021-08-23T14:54:07Z")

</div>

Intriguing. Well, I can try this myself this evening. See what happens.

What version of CMake are you using?

---

<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:** [August 23, 2021, 3:39pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/11 "2021-08-23T15:39:15Z")

</div>

Hm, the problem I get right now is that the linker wants access to the lfortran\_runtime library. And the linker that is picked up is the gcc linker.

---

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [August 23, 2021, 4:36pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/12 "2021-08-23T16:36:42Z")

</div>

> [@certik](#):
>
> … It thinks it is a Cray compiler. 🙂 But it works …

@certik, just curious as to what the LFortran team has done with CMake generators to configure and recognize LFortran: [cmake-generators(7) — CMake 3.17.5 Documentation](https://cmake.org/cmake/help/v3.17/manual/cmake-generators.7.html#makefile-generators)

Also have any of you also inquired at the CMake Discourse:

> **[VS generator and toolchain files](https://discourse.cmake.org/t/vs-generator-and-toolchain-files/1177/3)**
>
> The VS generator produces .vcxproj files and uses MSBuild to actually drive the build. The values of CMAKE\_{C,CXX}\_COMPILER are computed automatically from the compiler MSBuild chooses so setting them has no effect. With this generator we can...

---

<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:** [August 23, 2021, 4:57pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/13 "2021-08-23T16:57:00Z")

</div>

> [@Arjen](#):
>
> What version of CMake are you using?

I believe I used CMake 3.21.1

> [@Arjen](#):
>
> Hm, the problem I get right now is that the linker wants access to the lfortran\_runtime library. And the linker that is picked up is the gcc linker.

I fixed it yesterday in [Link on Windows from the lfortran driver (!1263) · Merge requests · lfortran / lfortran · GitLab](https://gitlab.com/lfortran/lfortran/-/merge_requests/1263), but we have not made a release yet, so it’s not in Conda yet.

My plan is to first fix LFortran to work well with fpm, including Windows. Once a few examples work reasonably well, I’ll make a release and ask for help again.

> [@FortranFan](#):
>
> @certik, just curious as to what the LFortran team has done with CMake generators to configure and recognize LFortran: [cmake-generators(7) — CMake 3.17.5 Documentation](https://cmake.org/cmake/help/v3.17/manual/cmake-generators.7.html#makefile-generators)

My understanding is that these generators are for generating the makefiles. We do not need to touch them. We need CMake support when it looks for a Fortran compiler.

> [@FortranFan](#):
>
> Also have any of you also inquired at the CMake Discourse:

That will be the next step after I am reasonably sure that thing work and compile using fpm on Windows (and other platforms). Then I would know the bug is most probably in CMake, and I’ll make a Conda release so that people can test it easily without having to compile from git.

---

<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:** [August 23, 2021, 5:00pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/14 "2021-08-23T17:00:26Z")

</div>

Indeed, the first step is to ensure that CMake acknowledges the lfortran compiler.

I will try and see how I can persuade gcc (or cl) to link to the lfortran library. The failure means that CMake cannot accept the lfortran compiler as something useable.

---

<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:** [August 23, 2021, 5:08pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/15 "2021-08-23T17:08:02Z")

</div>

> [@Arjen](#):
>
> I will try and see how I can persuade gcc (or cl) to link to the lfortran library. The failure means that CMake cannot accept the lfortran compiler as something useable.

This is already fixed in LFortran ([Link on Windows from the lfortran driver (!1263) · Merge requests · lfortran / lfortran · GitLab](https://gitlab.com/lfortran/lfortran/-/merge_requests/1263)), but you would need to use the latest master version from git.

---

<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:** [August 23, 2021, 5:23pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/16 "2021-08-23T17:23:08Z")

</div>

That is presenting a slight problem: I tried to use a plain WIndows command window, but the build procedure requires running a few shell scripts ;). I wil ltry it with MinGW instead (MinGW-w64/MSYS2 to be precise)

---

<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:** [August 23, 2021, 5:27pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/17 "2021-08-23T17:27:41Z")

</div>

Nice try: my laptop lacks utilities such as re2c and bison.

---

<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:** [August 23, 2021, 10:21pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/18 "2021-08-23T22:21:03Z")

</div>

Yes, one has to install them using Conda: [Installation - LFortran Documentation](https://docs.lfortran.org/installation/#build-from-git). I’ll ping you in a few days when we make a release, that way you can just install LFortran itself using Conda.

---

<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:** [August 24, 2021, 6:55am UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/19 "2021-08-24T06:55:09Z")

</div>

Good, an alternative would of course be to install the missing utilities and build from source.

(Slightly off topic:  
By the way, something very odd has happened: lfortran is no longer recognised as a command or program when I activate the lf environment, even though the PATH variable shows the directory where the program resides. If I type the full path and name, it does work. Before there was no such problem)

---

<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:** [August 24, 2021, 2:58pm UTC](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737/20 "2021-08-24T14:58:02Z")

</div>

> [@Arjen](#):
>
> By the way, something very odd has happened: lfortran is no longer recognised as a command or program when I activate the lf environment, even though the PATH variable shows the directory where the program resides. If I type the full path and name, it does work. Before there was no such problem)

Weird. I assume you tried a new terminal and loading the environment again.

I am considering eventually buying a Windows machine and try to develop LFortran there for a while, to get a feel for these things and to ensure everything just works. Until then, I can only make sure it works at the Windows CI, which it does.

[Next page](https://fortran-lang.discourse.group/t/lfortran-looking-for-some-help-from-a-windows-user/1737.md?page=2)
