How can I link Fortran code to preCICE?

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?

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")

In particular, look at the README of the solverdummy: fortran-module/examples/solverdummy at develop · precice/fortran-module · GitHub

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

3 Likes

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, make is running:

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

But I didn’t install precice with pkg-cofig :weary:

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

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?

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

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.

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.

1 Like

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)

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