# Compiling ElmerFEM using LFortran

**URL:** <https://fortran-lang.discourse.group/t/compiling-elmerfem-using-lfortran/6880>\
**Category:** Help\
**Created:** [November 29, 2023, 8:01pm UTC](https://fortran-lang.discourse.group/t/compiling-elmerfem-using-lfortran/6880 "2023-11-29T20:01:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eelis](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@eelis](https://fortran-lang.discourse.group/u/eelis)\
**Post date:** [November 29, 2023, 8:01pm UTC](https://fortran-lang.discourse.group/t/compiling-elmerfem-using-lfortran/6880/1 "2023-11-29T20:01:38Z")

</div>

Hello!

I am trying to compile ElmerFEM ([GitHub - ElmerCSC/elmerfem: Official git repository of Elmer FEM software](https://github.com/ElmerCSC/elmerfem)) using LFortran.

I am having some issues (as expected from an alpha stage compiler), but I do not want to spam the issue boards straight away because the blame might be on me. And there can be many issues between here and the successful compilation, so I’ll use this thread for asking around and for deciding if the issue should be reported to LFortran issue tracker (or that of ElmerFEM).

ElmerFEM is mainly a fortran code (F90), at least the part that I am interested in now (the ElmerSolver) and allows several 3rd party libraries to be linked in for various tasks (linear system solution, meshing, partitioning, mpi, …). Build automation is handled using cmake (trying to incorporate fpm is one other project that should be tried).

However, let’s start simple and use as little external libraries as possible:

```auto
export FC="/home/eelis/git/lfortran/src/bin/lfortran"
cmake .. -DWITH_MPI=FALSE

```

MPI is `TRUE` by default

First relevant error is here:

```auto
Run Build Command(s):/usr/bin/make -f Makefile cmTC_f0449/fast && /usr/bin/make -f CMakeFiles/cmTC_f0449.dir/build.make CMakeFiles/cmTC_f0449.dir/build
make[1]: Entering directory '/home/eelis/git/elmerfem/build/CMakeFiles/CMakeScratch/TryCompile-E47nlM'
Building Fortran object CMakeFiles/cmTC_f0449.dir/testFortranCompiler.f.o
/home/eelis/bin/lfortran -c /home/eelis/git/elmerfem/build/CMakeFiles/CMakeScratch/TryCompile-E47nlM/testFortranCompiler.f -o CMakeFiles/cmTC_f0449.dir/testFortranCompiler.f.o
e[0;31;1msemantic errore[0;0me[0;1m: function interface must be specified explicitly; you can enable implicit interfaces with `--implicit-interface`e[0;0m
 e[0;34;1m-->e[0;0m /home/eelis/git/elmerfem/build/CMakeFiles/CMakeScratch/TryCompile-E47nlM/testFortranCompiler.f:3:16
  e[0;34;1m|e[0;0m
e[0;34;1m3 |e[0;0m external sgemm
  e[0;34;1m|e[0;0m e[0;31;1m^^^^^ e[0;0m

e[0;1mNotee[0;0m: Please report unclear or confusing messages as bugs at
https://github.com/lfortran/lfortran/issues.
make[1]: *** [CMakeFiles/cmTC_f0449.dir/build.make:78: CMakeFiles/cmTC_f0449.dir/testFortranCompiler.f.o] Error 1
make[1]: Leaving directory '/home/eelis/git/elmerfem/build/CMakeFiles/CMakeScratch/TryCompile-E47nlM'
make: *** [Makefile:127: cmTC_f0449/fast] Error 2

```

Even if `--implicit-interface` is used, it just ends to an error where `sgemm` symbol is not found. So the issue is that `libblas` is not found. Gfortran compiles the whole project without problems.

I am wondering why in the case of LFortran, libblas is not found (should I compile that first btw.)? Is omitting the `--implicit-interface` functionality a “standard behaviour” among compilers?

Thanks!

edit. This may be a cmake configuration issue with lfortran

---

<div class="post-metadata">

**Author:** ![eelis](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@eelis](https://fortran-lang.discourse.group/u/eelis)\
**Post date:** [November 30, 2023, 5:39am UTC](https://fortran-lang.discourse.group/t/compiling-elmerfem-using-lfortran/6880/3 "2023-11-30T05:39:01Z")

</div>

Hmm… the actual problem is `find_package(BLAS REQUIRED)`  
Here is a small example:  
`CMakeLists.txt`:

```auto
cmake_minimum_required(VERSION 3.10)
enable_language(Fortran)
project(Hello)
add_executable(Hello hello.f90)
set_target_properties(Hello PROPERTIES LINKER_LANGUAGE Fortran)
find_package(BLAS REQUIRED)

```

`hello.f90`:

```auto
print *, "hello!"; end

```

Put in the same folder and run  
`mkdir build; cd build; FC="/home/eelis/git/lfortran/src/bin/lfortran" cmake ..`

with `gfortran` I have no issue.

FYI @certik

---

<div class="post-metadata">

**Author:** ![eelis](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@eelis](https://fortran-lang.discourse.group/u/eelis)\
**Post date:** [November 30, 2023, 8:33am UTC](https://fortran-lang.discourse.group/t/compiling-elmerfem-using-lfortran/6880/4 "2023-11-30T08:33:49Z")

</div>

I wrote a related issue: [Unhandled exception with external libblas subroutine · Issue #2924 · lfortran/lfortran · GitHub](https://github.com/lfortran/lfortran/issues/2924)

---

<div class="post-metadata">

**Author:** ![nncarlson](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/nncarlson/32/1175_2.png) [@nncarlson](https://fortran-lang.discourse.group/u/nncarlson)\
**Post date:** [November 30, 2023, 2:35pm UTC](https://fortran-lang.discourse.group/t/compiling-elmerfem-using-lfortran/6880/5 "2023-11-30T14:35:58Z")

</div>

This isn’t a problem with Lfortran. The blas library isn’t part of Fortran. It’s a third party library (TPL), of which there a many available implementations. Your system happens to include one that was compiled with gfortran which is why the `find_package(BLAS)` is successful when using gfortran. Code compiled with one Fortran compiler are not generally compatible with code compiled by another. You’re going to need to compile a version of the blas using Lfortran (and then arrange for cmake to find that one). Same for any other Fortran library that ElmerFEM uses. And when you get to turning MPI back on, you’ll need to build a version of the MPI library using Lfortran for the Fortran compiler (assuming ElmerFEM uses the Fortran MPI interface). Things get compilicated when you’re building a program that relies on TPL.

---

<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:** [November 30, 2023, 3:11pm UTC](https://fortran-lang.discourse.group/t/compiling-elmerfem-using-lfortran/6880/6 "2023-11-30T15:11:45Z")

</div>

@eelis Thanks for trying LFortran! We are still in alpha, meaning it is expected you will hit issues like these when trying it on a new code. Go ahead and report them all into our issue tracker and we’ll fix them. Ideally if you can figure out a small reproducible example, those are the best bug reports that we can fix quickly.

Regarding `print *, "hello!"; end`, I tried it in LFortran, that works for me. So the issue is likely what @nncarlson said, you might be mixing several Fortran compilers in the same project. That never works in general.
