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

Confusion about use of include files

WSinc
New Contributor I
235 Views

I have a program that uses a file with PARAMETER in it, so I want all the subroutines to include that with an include statement.

The file is typed as an INC file, i.e. PARAMS.INC

The subroutines have no trouble referencing this file, but the main program cannot open it.

I get an error massage type #5102.

 

I was wondering why the MAIN program cannot reference the same file that all the subroutines can reference?

That is the the same project - Is there a way around this ?

0 Kudos
6 Replies
IanH
Honored Contributor II
235 Views

When I'm responsible for errors I just get boxed around the ears, never a massage.

There's no special restriction on main programs with respect to include line.  Include lines simply do text inclusion into the stream of source code that the compiler ultimately sees.

I'd suspect something like a spelling mistake in the file name being included, or the search path for include files not including the path that actually has the file.

Modules provide an alternative to include files, with some additional benefits.  For example, modules operate on a higher level than include files - they operate on the level of the Fortran entities in the program.  If you define your constant in a module, that definition is complete, any scope that uses the module has access to the exact same entity.  An include file is just source, the meaning of the thing defined by that source can be changed by other source code in the scope where the relevant include line appears.

A hybrid approach, useful for migration, is to include the file into a module.

0 Kudos
WSinc
New Contributor I
235 Views

Well, all the INCLUDE statements are exactly the same spelling....................

 

So I dont understand what you are talking about.

0 Kudos
mecej4
Honored Contributor III
235 Views

Are all the source files in the same directory? Where is the include file located relative to that directory? Have you specified additional directories to search for include files?

0 Kudos
WSinc
New Contributor I
235 Views

I think the problem was caused by the MAIN program being in the directory one level higher than the others.

Why the compiler would do that, I don't understand.

 

Anyway, I will use the MODULE approach instead, see what happens.

0 Kudos
IanH
Honored Contributor II
235 Views

The search path for an include file includes the directory that the file with the include line is in.  If the file being included is another directory that is not also on the search path in some other way, then the compiler needs to be told to search that directory.

The compiler doesn't choose where input files go.

The Visual Studio environment creates new items being added to a project in the same directory as the project file, depending on how you create/add the item.

0 Kudos
mecej4
Honored Contributor III
235 Views

billsincl wrote:
I think the problem was caused by the MAIN program being in the directory one level higher than the others.

Anyway, I will use the MODULE approach instead, see what happens.

If the .mod files are not in the same directory as the source files that USE those modules, you may have similar issues as you did with include files, and you may need to specify a non-default search path for the module files.

0 Kudos
Reply