# How can I link Fortran code to preCICE?

**URL:** https://precice.discourse.group/t/how-can-i-link-fortran-code-to-precice/1930
**Category:** Using preCICE
**Tags:** fortran
**Created:** [May 16, 2024, 7:46pm UTC](https://precice.discourse.group/t/how-can-i-link-fortran-code-to-precice/1930 "2024-05-16T19:46:54Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Abbas\_Ballout](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/abbas_ballout/32/2340_2.png) [@Abbas\_Ballout](https://precice.discourse.group/u/Abbas_Ballout)
#### Post date: [May 16, 2024, 7:46pm UTC](https://precice.discourse.group/t/how-can-i-link-fortran-code-to-precice/1930/1 "2024-05-16T19:46:54Z")

</div>

I have installed and compiled precice and I checked that it runs by running the dummy examples. It also couples with dealii code.  
Now I am trying to couple precice with a fortran library. The library uses a make file to build the solvers which I believe I should edit and add the precice library to build against. I ve been trying to do this for a while now with no luck. I tried to look at the make file generated by the cmake fortran dummy example but it doesn’t seem like there are any hints there.  
Anyone with a make file to spare? Any adaptors I can look at for hints?

---

<div class="post-metadata">

### Author: ![Makis](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/makis/32/25_2.png) [@Makis](https://precice.discourse.group/u/Makis)
#### Post date: [May 17, 2024, 12:48pm UTC](https://precice.discourse.group/t/how-can-i-link-fortran-code-to-precice/1930/2 "2024-05-17T12:48:27Z")

</div>

Hi @Abbas_Ballout,

have you already found the fortran module? That could help: [GitHub - precice/fortran-module: A Fortran module for the Fortran bindings of preCICE (formerly "f2003 bindings")](https://github.com/precice/fortran-module)

In particular, look at the README of the solverdummy: [fortran-module/examples/solverdummy at develop · precice/fortran-module · GitHub](https://github.com/precice/fortran-module/tree/develop/examples/solverdummy)

Note that we are planning to work a lot on the fortran module in the next months, and things will change (for the better).

---

<div class="post-metadata">

### Author: ![Abbas\_Ballout](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/abbas_ballout/32/2340_2.png) [@Abbas\_Ballout](https://precice.discourse.group/u/Abbas_Ballout)
#### Post date: [May 18, 2024, 4:15pm UTC](https://precice.discourse.group/t/how-can-i-link-fortran-code-to-precice/1930/3 "2024-05-18T16:15:26Z")

</div>

I ran make inside the fortran\_module/example/solver\_dummy and I am getting this error:

```
f77 -std=f2003 -g solverdummy.f90 -o solverdummy -I../.. -L/usr/local/lib -lprecice
/usr/bin/ld: cannot find -lprecice: No such file or directory

```

According to the [read.me](http://read.me), make is running:

```
gfortran solverdummy.f90 -I../.. -L$(pkg-config --libs libprecice)

```

But I didn’t install precice with pkg-cofig 😩

---

<div class="post-metadata">

### Author: ![Abbas\_Ballout](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/abbas_ballout/32/2340_2.png) [@Abbas\_Ballout](https://precice.discourse.group/u/Abbas_Ballout)
#### Post date: [May 20, 2024, 7:15pm UTC](https://precice.discourse.group/t/how-can-i-link-fortran-code-to-precice/1930/4 "2024-05-20T19:15:18Z")

</div>

Edit I have this line in bashrc tho:

```
export PKG_CONFIG_PATH=$PRECICE_PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH

```

The error I am always getting is:

```
cannot find -lprecice: No such file or directory

```

I have all of these present in bashrc

```
PRECICE_PREFIX=/home/abbas/precice/build
export PATH=$PRECICE_PREFIX/bin:$PATH
export LD_LIBRARY_PATH=$PRECICE_PREFIX/lib:$LD_LIBRARY_PATH
export CPATH=$PRECICE_PREFIX/include:$CPATH
export PKG_CONFIG_PATH=$PRECICE_PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH
export CMAKE_PREFIX_PATH=$PRECICE_PREFIX:$CMAKE_PREFIX_PATH

```

---

<div class="post-metadata">

### Author: ![Abbas\_Ballout](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/abbas_ballout/32/2340_2.png) [@Abbas\_Ballout](https://precice.discourse.group/u/Abbas_Ballout)
#### Post date: [May 21, 2024, 6:45pm UTC](https://precice.discourse.group/t/how-can-i-link-fortran-code-to-precice/1930/5 "2024-05-21T18:45:21Z")

</div>

Okay.  
I figured something out.  
Since I compiled from source, my config should have been given by just build.

```
/home/abbas/precice/build

```

The external code compiles with precice, I added the fortran line “CALL precicef\_create(“participantName”, “config”, 1, 1)” to the fortran code and now and now I am getting:

```
 error while loading shared libraries: libprecice.so.3: cannot open shared object file: No such file or directory

```

Does this mean that I have to use the fortran module?

---

<div class="post-metadata">

### Author: ![Makis](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/makis/32/25_2.png) [@Makis](https://precice.discourse.group/u/Makis)
#### Post date: [May 22, 2024, 8:04am UTC](https://precice.discourse.group/t/how-can-i-link-fortran-code-to-precice/1930/6 "2024-05-22T08:04:06Z")

</div>

> [@Abbas\_Ballout](#):
>
> But I didn’t install precice with pkg-cofig

pkg-config is not a package manager, but a standard way of telling programs where to find libraries during compilation.

Since you are building from source, you are also supposed to run `make install` to install the files into the directory you set up as prefix: [Building from source - Preparation | preCICE - The Coupling Library](https://precice.org/installation-source-preparation.html)

This prefix should be different from your build directory.

In the installation directory, you will also find a `.pc` file with these paths, check if they are correct.

> [@Abbas\_Ballout](#):
>
> Does this mean that I have to use the fortran module?

This error says that the whole library was not found, not that a specific symbol was not resolved. You generally can use the intrinsic Fortran bindings directly, you don’t need to use the module.

---

<div class="post-metadata">

### Author: ![Abbas\_Ballout](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/abbas_ballout/32/2340_2.png) [@Abbas\_Ballout](https://precice.discourse.group/u/Abbas_Ballout)
#### Post date: [May 22, 2024, 5:52pm UTC](https://precice.discourse.group/t/how-can-i-link-fortran-code-to-precice/1930/7 "2024-05-22T17:52:00Z")

</div>

I got it now thanks.  
For future users, since I was compiling from source I had to be a bit conscious with where I set LD\_LIBRARY\_PATH and PKG\_CONFIG\_PATHS so something like this:

```
PRECICE_PREFIX=/home/abbas/precice/build
export PATH=$PRECICE_PREFIX/bin:$PATH
export LD_LIBRARY_PATH=$PRECICE_PREFIX/:$LD_LIBRARY_PATH
export CPATH=$PRECICE_PREFIX/include:$CPATH
export PKG_CONFIG_PATH=$PRECICE_PREFIX/pkgconfig:$PKG_CONFIG_PATH
export CMAKE_PREFIX_PATH=$PRECICE_PREFIX:$CMAKE_PREFIX_PATH

```

as opposed to what I pasted above. (sanza lib)

---

<div class="post-metadata">

### Author: ![system](https://global.discourse-cdn.com/free1/uploads/precice/original/1X/67d2a5fa6f80e597e2267ff17fa8c1673cd11caa.svg) [@system](https://precice.discourse.group/u/system)
#### Post date: [May 25, 2024, 5:52pm UTC](https://precice.discourse.group/t/how-can-i-link-fortran-code-to-precice/1930/8 "2024-05-25T17:52:54Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
