Fpm: preprocessor directives

Created on 7 Jul 2020  Â·  7Comments  Â·  Source: fortran-lang/fpm

I am trying to build a simple logging library I wrote some time ago. In order to get file names and current line number I use a small preprocessor file: macros.h that only contains:

#ifndef FL
#define FL __FILE__
#endif

#ifndef LN
#define LN __LINE__
#endif

and I include it at the beginning of the file I want to use it like #include "macros.h"
I get this error when I am trying to build with fpm:

Exit code: 1
Stderr:
test/main.f90:1:2:

    1 | #include "marcos.h"
      |  1
Warning: Illegal preprocessor directive
test/main.f90:8:20:

    8 |     call log%info(FL, LN, 'Passed')
      |                    1
Error: Symbol ‘fl’ at (1) has no IMPLICIT type
compilation terminated due to -fmax-errors=1.

Note that this is with main.f90
When I changed the name to main.F90and the fpm.toml file accordingly:

[[test]]
name="runTests"
source-dir="test"
main="main.F90"

Then I got this error:

Exit code: 1
Stderr:
test/main.F90:2:2:

    2 | program test
      |  1~~~~~~~~~
Fatal Error: marcos.h: No such file or directory
compilation terminated.

Any suggestions of what I may be doing wrong?

Most helpful comment

Glad that fixed it!
We may potentially need an option to manually specify an include path or have a standard include folder (include/) which contains text inclusions; consider the case if you needed to use macros.h from both src/ and test/

All 7 comments

Is your include file macros.h or marcos.h? Currently your f90 file tries to include marcos.h but perhaps the file is called macros.h.

As discussed in #78, the .f90 files should also be run through the pre-processor, perhaps no by default (for speed reasons), but if you enable it in the fpm.toml.

@milancurcic You are correct that was a typo, but the problem persists after correcting it.

Hi @smeskos, is the macros.h file in the same folder as the .f90 files that include it?

@LKedward right, that was the problem. I had this in src/ but I wanted to use it in test/. Thank you!!

Glad that fixed it!
We may potentially need an option to manually specify an include path or have a standard include folder (include/) which contains text inclusions; consider the case if you needed to use macros.h from both src/ and test/

Thank you again. I am closing this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

certik picture certik  Â·  3Comments

awvwgk picture awvwgk  Â·  9Comments

lauvergn picture lauvergn  Â·  7Comments

certik picture certik  Â·  8Comments

aslozada picture aslozada  Â·  5Comments