Skip to content

preprocessor directives #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
smeskos opened this issue Jul 7, 2020 · 7 comments
Closed

preprocessor directives #113

smeskos opened this issue Jul 7, 2020 · 7 comments

Comments

@smeskos
Copy link

smeskos commented Jul 7, 2020

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?

@milancurcic
Copy link
Member

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.

@certik
Copy link
Member

certik commented Jul 7, 2020

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.

@smeskos
Copy link
Author

smeskos commented Jul 7, 2020

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

@LKedward
Copy link
Member

LKedward commented Jul 7, 2020

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

@smeskos
Copy link
Author

smeskos commented Jul 7, 2020

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

@LKedward
Copy link
Member

LKedward commented Jul 7, 2020

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/

@smeskos
Copy link
Author

smeskos commented Jul 7, 2020

Thank you again. I am closing this.

@smeskos smeskos closed this as completed Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants