Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
8 Views

Compiler Directives in Code:Blocks

In Windows, I have long used iFort's simple compiler directive facility for conditional compilation.

https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-compiler-directives

for example

!DIR$ IF(FOO==1)

do something

!DIR$ ELSE

do something else

!DIR$ ENDIF

In Windows Developer Studio the value of FOO can be set globally in the project properties page in

Configuration Properties > Fortran > Preprocessor > Preprocessor Definitions

in the form FOO=1;FIE=0;FUM=1 ... etc.

These definitions are then applied to all files in the project. Note that this does not require the "Preprocess Source File" property to be Yes.

I am now trying to get this to work in Linux where I am running Code:Blocks for Fortran (CBFortran) as the IDE. CBFortran offers a project build options page with many of the compiler options, but no "Preprocessor Definitions" line.  I would appreciate some guidance on how to use Intel's Compiler Directives feature in this context.

....

 

0 Kudos
5 Replies
Highlighted
Beginner
8 Views

Correction: !$DIR should be

Correction: !$DIR (as originally posted) should be !DIR$ is the example. I corrected it.

0 Kudos
Highlighted
Black Belt
8 Views

From the compiler's

From the compiler's perspective, this is the same as using fpp and one uses -D to define preprocessor symbols on the command line. Your question is really directed at Code:Blocks, it's not an Intel issue.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
8 Views

!DIR$ are vendor specific

!DIR$ are vendor specific directives, otherwise are comments

You may need to make your !DIR$ directives safe for Code:Blocks

!DIR$ IF(FOO==1)
  iFrom = from_something
  iTo = to_something
  iStep = step_something
!DIR$ ELSE
  iFrom = from_something_else
  iTo = to_something_else
  iStep = step_something_else
!DIR$ ENDIF
do i=iFrom, iTo, iStep
  ...

(you will also need to -DFOO... in  your compiler option)

Your code may still be non-portable, at least to those compilers not supporting !DIR$...

Jim Dempsey

0 Kudos
Highlighted
Black Belt
8 Views

The question was how to

The question was how to specify defined symbols using the Code:Blocks UI. If Code:Blocks allows additional command line options (I don't use it), you can add:

-DFOO=-1 -DFIE=0

etc.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
8 Views

I found it and verified that

I found it and verified that it works. It was in Build Options>Compiler Settings># defines.

This tab is initially hidden in the GUI, but appears if you repeatedly click on the right arrow in the row of tabs.

 

Thanks to everyone who replied.

0 Kudos