LFortran looking for some help from a Windows user

If we build lfortran with mingw and link it against an mingw-compatible LLVM, it works using ld linker from the mingw toolchain, no need to install Visual Studio.

1 Like

That is my other question on Windows: can one LLVM handle both MSVC and mingw compatible object files? Then we can distribute just one LFortran binary that can handle both and users would have to choose via a command line option.

Well, I just started a new Anaconda prompt and this is the session:

(base) C:\Users\markus>conda activate lf

(lf) C:\Users\markus>lfortran
‘lfortran’ is not recognized as an internal or external command,
operable program or batch file.

(lf) C:\Users\markus>

I may be doing something wrong, but I have no idea what. I installed the lf environment as per the receipe.

(I will spare you the PATH environment variable, but it starts as:

(lf) C:\Users\markus>path
PATH=C:\Users\markus.julia\conda\3\envs\lf;C:\Users\markus.julia\conda\3\envs\lf\Library\mingw-w64\bin;C:\Users\markus.julia\conda\3\envs\lf\Library\usr\bin;C:\Users\markus.julia\conda\3\envs\lf\Library\bin;C:\Users\markus.julia\conda\3\envs\lf\Scripts;C:\Users\markus.julia\conda\3\envs\lf\bin;C:\Users\markus.julia\conda\3\condabin;…

lfortran.exe lives in c:\Users\markus.julia\conda\3\Library\bin\ - that is indeed not included the path)

1 Like

I don’t how to implement it in lfortran, but I know clang is able to generate code for both MSVC and mingw:

clang --help
…
--target=<value>        Generate code for the given target

Use x86_64-w64-windows-gnu for mingw compatible object files, x86_64-pc-windows-msvc for Visual Studio compatible object files, etc.

Somehow it stopped being linked in the lf environment. You will probably have to recreate the environment.

Thanks for this, I think this is a good approach. I created an issue Add --target option to select code generation target (#545) · Issues · lfortran / lfortran · GitLab to implement the same design in LFortran.

I just tried that:

  • While I had the command window open in which I had issued the command “conda create -n lf” (as per the documentation) and activated the lf environment, lfortran was recognised as a program.
  • When I closed that and opened a new command window, issued “conda activate lf”, I got the same error again!

I am no expert on the mechanics of these environments, but at least I have a workaround.

1 Like

Sorry about that. There might be bugs in Conda also on Windows. If you know of a better way to reliably distribute LFortran on Windows, let me know. What I like about Conda is that at least it provides a binary on Windows, macOS (Intel+Arm) and Linux that works, as long as you can get Conda itself working.

It is the first time I have seen this odd behaviour, but I would ask my colleagues about possible bugs that cause this. More important of course is how to get around them. Well, the workaround is clear enough :wink:
(for me that is).

1 Like

Not sure if it helps.
But I hear you guys talking about linker, here I contribute a stupid and perhaps useless makefile, which I use for a small code of mine. Once the gnu make is installed on windows, I can just type make to compile my code in windows using intel fortran, just like the make in linux. Here is the makefile for intel Fortran (OneAPI).
For intel Fortran I always enable /LARGEADDRESSAWARE in visual studio, but not sure how to do it in makefile. I spend sometime and figured it out. Here it is,


EXEC = rpem.exe
FC = ifort.exe
LINKER = /link

IDIR =
FFLAGS=/nologo /MP /O3 /QxHost /assume:buffered_io /heap-arrays0 /Qipo /libs:static /threads /Qmkl:cluster
F77FLAGS=$(FFLAGS) -fdefault-real-8 -fdefault-double-8 # gfortran only.
LDFLAGS=/INCREMENTAL:NO /LARGEADDRESSAWARE
LIBS =

.SUFFIXES:
.SUFFIXES: .obj .f .f90

.f90.obj:
(FC) (FFLAGS) /c $<

%.obj: %.mod

OBJECTS=
EM_mix.obj
ran.obj
samplers.obj

EM_mix: (OBJECTS) (FC) /exe:(EXEC) (OBJECTS) (LIBS) (LINKER) /out:(EXEC) (LDFLAGS)

clean:
@del /q /f $(EXEC) *.mod *.obj *~ > nul 2> nul

not that in windows rm -f does not work, so use del instead.

> nul 2> nul just to suppress some redundunt mesage.

EM_mix.obj: ran.obj samplers.obj EM_mix.f90
(FC) (FFLAGS) /c EM_mix.f90

ran.obj: ran.f90
(FC) (FFLAGS) /c ran.f90

samplers.obj: ran.obj samplers.f90
(FC) (FFLAGS) /c samplers.f90


Below is a makefile for gfortran in windows,

EXEC = rpem.exe
FC = gfortran.exe
IDIR =
FFLAGS = -march=native -Ofast -m64
F77FLAGS=$(FFLAGS) -fdefault-real-8 -fdefault-double-8 # gfortran only.
LIBS =

.SUFFIXES:
.SUFFIXES: .o .f .f90

.f90.o:
(FC) (FFLAGS) -c $<

%.o: %.mod

OBJECTS=
EM_mix.o
ran.o
samplers.o

EM_mix: (OBJECTS) (FC) -o ./(EXEC) (OBJECTS) $(LIBS)

clean:
@del /q /f $(EXEC) *.mod *.o *~ > nul 2> nul

not that in windows rm -f does not work, so use del instead.

> nul 2> nul just to suppress some redundunt mesage.

EM_mix.o: ran.o samplers.o EM_mix.f90
(FC) (FFLAGS) -c EM_mix.f90

ran.o: ran.f90
(FC) (FFLAGS) -c ran.f90

samplers.o: ran.o samplers.f90
(FC) (FFLAGS) -c samplers.f90

Sorry if this post is irrelevant. Just try to contribute whatever I have before sleep.