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

Module compiles without warning of missing routines?

chauvjo
Novice
648 Views

I have a project setup as a static library in Visual Studio 2015.  After I finish each module, I do a test compile to catch any errors and in particular if I forgot to add the necessary USE statements.   I just finished a large module which contains numerous calls to subroutines in other modules (already completed and compiled).  The module compiled with only warnings about missing functions.  When I added the appropriate USE statements for the functions, the module compiled without any errors or warnings despite missing all the USE statements containing the subroutine definitions.   I did a test compile with all USE statements removed in case there was some hidden propagation of the needed subroutines.  The module compiled with only messages about the functions.

Can someone help explain why the compiler is not complaining about the missing subroutine definitions?  And why it is complaining about the missing function definitions?  By the way, before compiling the latest module, I make sure all the other modules have been compiled.

Here are my compiler options:

/nologo /debug:full /Od /stand:f08 /warn:declarations /warn:unused /warn:interfaces /module:"x64\Debug\\" /object:"x64\Debug\\" /Fd"x64\Debug\vc140.pdb" /list:"x64\Debug\static_library.lst" /traceback /check:bounds /check:stack /libs:dll /threads /dbglibs /c

Thanks….

0 Kudos
10 Replies
jimdempseyatthecove
Honored Contributor III
648 Views

>> the module compiled without any errors or warnings despite missing all the USE statements containing the subroutine definitions. 

Do you mean to say:

you have a module with INTERFACE declarations to subroutines contained in a different module in a CONTAINS section?

If this is what you mean, then you have multiple declarations of the interface (one in the INTERFACE block in one module, and the actual interface in the module with the CONTAINS contained subroutine). This is not permitted.

Jim Dempsey

0 Kudos
mecej4
Honored Contributor III
648 Views

Fortran has a long tradition of separate compilation. Each program unit can be compiled independently of the rest. It is only at link time that the object files from all units that form a program are linked together, and a list of unsatisfied externals printed, if any.

You are confusing compiling and linking, which is understandable because the driver, ifort.exe, depending on the switches used, is capable of compiling only, linking only, or both. If you use the IDE, again things are done for you unseen, and it may not be clear to you what is being done.

When compiling modules, you should use the /c switch. If you do not, you will get lots of linker errors about unsatisfied externals, but it is easy to make a habit of ignoring such messages.

When you leave out USE statements, the compiler will assume that calls to external subroutines and functions may be made with implicit interfaces. The compilation will proceed, but after linking the program may fail to run properly if the actual interface does not agree with the implicit interface.

0 Kudos
chauvjo
Novice
648 Views

Thanks for the replies. All my subroutines are "contained" in other modules so my understanding is I do not need to add INTERFACE blocks to any of my routines. None of the modules have INTERFACE blocks.  I still not sure why I received warning about missing functions and not subroutines.  So if I understand correctly, I need to create a command line project, add a dummy main program and do a full compile and link to have the compiler catch all the missing USE statements or am I still missing something? If so, how can I have the compiler caught missing subroutine definitions?

Thanks....

0 Kudos
mecej4
Honored Contributor III
648 Views

When Fortran 2015 is implemented in compilers, you will be able to use the IMPLICIT NONE(EXTERNAL) declaration.

You can also compile multiple source files with the /warn:interfaces option. There are a number of Ifort options pertaining to interfaces, which you may want to become familiar with.

0 Kudos
chauvjo
Novice
648 Views
0 Kudos
jimdempseyatthecove
Honored Contributor III
648 Views

When you compile a module, if there is/are CONTAINS code, or initialized data, the compiler produces 2 output files:

1) a .mod file, which is somewhat like a C/C++ pre-compiled header
2) a .o (or .obj if on Windows)

The .mod file is the one USE's
The .o file is what is to be linked into your executable/library/so

Jim Dempsey
 

0 Kudos
andrew_4619
Honored Contributor II
648 Views

It is quite simple, a function must have a declaration of type in the routine that call its or an explicit interface. So the absence of both is an error. A subroutine to not have a type so there is no error, it is just assumed to be external if there is no interface.

Roll on Fortran 2015 with IMPLICIT NONE(EXTERNAL) which mean the subroutines without an explict interface will generate and error. This will save time (where everything is in modules) as we will get compile time errors rather than having a link error at the very end..

 

0 Kudos
IanH
Honored Contributor II
648 Views

andrew_4619 wrote:

It is quite simple, a function must have a declaration of type in the routine that call its or an explicit interface. So the absence of both is an error. A subroutine to not have a type so there is no error, it is just assumed to be external if there is no interface.

Roll on Fortran 2015 with IMPLICIT NONE(EXTERNAL) which mean the subroutines without an explict interface will generate and error. This will save time (where everything is in modules) as we will get compile time errors rather than having a link error at the very end.

That should be "...when subroutines without the external attribute...".  They will still be permitted to have an implicit interface.

0 Kudos
andrew_4619
Honored Contributor II
648 Views

I have asked Santa IMPLICIT NONE(EXTERNAL) but I think I will not have been good enough this year.....

 

0 Kudos
IanH
Honored Contributor II
648 Views

I once asked Santa about implementing a compiler warning, separate to the language rules (existing or future), whenever a procedure with an implicit interface was referenced or otherwise appeared.  This was after queueing up at the local shopping centre for half an hour.  Santa just looked confused (and was complaining about my weight), so after I had my picture taken, I gave him a copy of ISO 1539-1:2010.

0 Kudos
Reply