Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Compiler Directives in Code:Blocks

rorban
Beginner
1,008 Views

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
rorban
Beginner
1,008 Views

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

0 Kudos
Steve_Lionel
Honored Contributor III
1,008 Views

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.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,008 Views

!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
Steve_Lionel
Honored Contributor III
1,008 Views

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.

0 Kudos
rorban
Beginner
1,008 Views

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
Reply