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

Using mod files

jjgermis
Beginner
2,727 Views

Hi,

I undestand the idea of modules andlibraries. My actual problem is a step-by-step working example. If I use some of IVF libraries and modules everthing seems to work fine. Here is what I did:

Created a new project with Microsoft Visual Studio and add a source file to the project with the following code:

program

use_mod

use ifport

implicit none

end

program

This example I can compile and build without any problems. When I replace use ifortmy own module it won't compile or build. If I call my module module mymodule saved in mods.f90 what are the exact steps I need to do?

When I look in %ifort_compiler10%ia32lib and %ifort_compiler10%ia32include I find ifport.lib and ifport.mod. Which corresponds with how understand the environment variables. Only when I add my stuff is does not seems to work.

Johannes

0 Kudos
3 Replies
Steven_L_Intel1
Employee
2,727 Views
Your module is in a source file mods.f90, right? Simply add that source file to your project - that's all you have to do (other than adding the USE line as needed.) Visual Studio will determine the correct order to compile the files, will compile the module source first and place the compiled .mod file in the "output" directory which is added to the "include" path in a project automatically.

It works for modules such as ifport because the path to the IA32INCLUDE folder is automatically added to the list of include directories, where module files are looked for.

Note that compiling a module also results in an object file, which will automatically get linked in if the source was part of your project.

If you have a separate library project that builds the modules, you have to make the library project a "dependent" of the parent project AND add the library project's "output" folder to the list of "additional include directories" for the parent project - that last is not done automatically.
0 Kudos
jjgermis
Beginner
2,727 Views

Hi Steve,

my module is in a source file. Adding the source to my project is what I would like to avoid since I use the same module in multiple programs. I also created a userincludewhichI added to my environment variable.This means that my user include directory should be added to the list of include directories bymeans of the environment variable. Or should I add this to some project property in Visual Studio?

Using Visual Studio should I use Project -> Properties or Tools -> Options to find the variables that I have to change. I am new to IVF and Visual Studio.

With my mods.f90 I would like to create module.mod and module.lib (or module.dll) then copy them inmy include and lib directories. And then use them in the same way as ifort for example.

Johannes

0 Kudos
jimdempseyatthecove
Honored Contributor III
2,727 Views

Compilation of a module file creates two output files: file.MOD and file.OBJ (sounds like you are aware of this)

The subsequent mod file must be in the INCLUDE path for the USE to work.

If the file.MOD contains only type and interface information (no data) then the .OBJ file need not be linked in with the application.

If the MOD file contains data, then you must link in the .OBJ file of the module (which you may stick into a .LIB file if you wish).

Visual Studio is a bit peculiar in this respect.

If you make your application dependent on the project of the module (sounds like not what you want) then the resultant .OBJ file will be linked into the application and source directory for the module (where the .MOD file is generally written to) is implicitly in your INCLUDE path. So nothing seems to be required of you to get the application to link. Although sometimes I have had to explicitly add the location of the .MOD file to the include directory.

If you build an application without the .MOD project in your dependency then you would generally place these files into your distributables directory and then to build your application you would have to add that directory to the INCLUDE path .AND. add the file.OBJ or yourLib.LIB to the link (which can be done in VS with add existing item and indicating the .OBJ or .LIB in lieu of a source file).

Jim Dempsey

0 Kudos
Reply