Hello! I’ve been trying to figure out the correct options to make linting work with Modern Fortran extension in VS Code. My code uses the PETSc library, and the library uses MPI. The linting compiler is having trouble finding the modules and declarations, etc. I have attached a screenshot demonstrating the problem:
(SNES, Vec, PetscErrorCode are types defined in the library, in “use petscsnes” there is also a warning that this module cannot be found in project)
I have added the include directories to extension settings as well as various compiler flags necessary for the program to compile.
I have tested manual compilation with gfortran with these flags and my program compiles just fine. The program itself is an example program from the PETSc library. Here is the command line I used to successfully compiling the example
gfortran -I/usr/lib/x86_64-linux-gnu/openmpi/include -I/usr/lib/petscdir/petsc3.12/x86_64-linux-gnu-real/include -L/usr/lib/x86_64-linux-gnu/openmpi/lib -L/usr/lib/petscdir/petsc3.12/x86_64-linux-gnu-real/lib -Wl,--copy-dt-needed-entries -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh -lmpi -o ex1f ex1f.F90 -lpetsc_real -lm
The settings.json contains the following lines relating to Modern Fortran extension:
"fortran.fortls.maxLineLength": 132,
"fortran.fortls.path": "/home/yuhongrui/.local/bin/fortls",
"fortran.linter.extraArgs": [
"-w",
"-L/usr/lib/x86_64-linux-gnu/openmpi/lib",
"-Wl,--copy-dt-needed-entries",
"-lmpi_mpifh",
"-lmpi -lpetsc_real",
"-lmpi_usempi_ignore_tkr",
"-lm",
"-lmpi_usempif08",
"-L/usr/lib/petscdir/petsc3.12/x86_64-linux-gnu-real/lib"
],
"fortran.linter.includePaths": [
"/usr/lib/petscdir/petsc3.12/x86_64-linux-gnu-real/include",
"/usr/lib/x86_64-linux-gnu/openmpi/include",
"${workspaceFolder}/fortran_mods"
],
"fortran.linter.modOutput": "${workspaceFolder}/fortran_mods",
"fortran.linter.compiler": "gfortran",
"fortran.linter.compilerPath": "/usr/bin/gfortran",
"fortran.experimental.keepInitDiagnostics": false,
"fortran.fortls.excludeDirectories": [
"/home/yuhongrui/.vscode-server",
"/home/yuhongrui/smagrad-dtn"
],
"fortran.linter.initialize": false
I really appreciate any suggestion you might have. Thanks a lot!