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

Problem with *.mod in USE directive

merrittr
Beginner
1,051 Views

Hi

I am porting some windows fortran code to linux.

the command I use to compile is:

ifort -assume protect_parens *.f* > dump.txt 2>&1

any of the .for or .f90 files that have statements like:

use GlobalConsts
use DataTypes
refering to the .mod files which I compiled using

ifort GlobalConsts.f90 and put the resulting .mod in the same directory as the source file USEing the mod

the dump file gives me (it cant see any of the vars in globalconstants???):

/tmp/ifortQQ57xF.o: In function `addboundaryconditions_':
AddBoundaryConditions.f90:(.text+0x14): undefined reference to `globalconsts_mp_explicit_boundary_conditions_'
/tmp/ifortzNt23D.o: In function `adddefaults_':
AddDefaults.for:(.text+0x13): undefined reference to `globalconsts_mp_mobil_unit_'
AddDefaults.for:(.text+0x1b): undefined reference to `globalconsts_mp_default_mob_'
AddDefaults.for:(.text+0x2b): undefined reference to `globalconsts_mp_charge_unit_'
AddDefaults.for:(.text+0x33): undefined reference to `globalconsts_mp_default_charge_'
AddDefaults.for:(.text+0x3c): undefined reference to `globalconsts_mp_diff_unit_'
AddDefaults.for:(.text+0x44): undefined reference to `globalconsts_mp_default_diff_'
AddDefaults.for:(.text+0x58): undefined reference to `globalconsts_mp_empty_'
AddDefaults.for:(.text+0xe8): undefined reference to `globalconsts_mp_empty_'
AddDefaults.for:(.text+0x129): undefined reference to `globalconsts_mp_empty_'
AddDefaults.for:(.text+0x1d1): undefined reference to `globalconsts_mp_empty_'
/tmp/ifortXWhXzC.o: In function `addfiles_':
AddFiles.for:(.text+0x1b): undefined reference to `globalconsts_mp_max_comps_'
AddFiles.for:(.text+0x136): undefined reference to `globalconsts_mp_tag_'
/tmp/iforteqxS5A.o: In function `additem_':
AddItem.for:(.text+0x10): undefined reference to `globalconsts_mp_max_comps_'
AddItem.for:(.text+0x47): undefined reference to `globalconsts_mp_empty_'
AddItem.for:(.text+0xdc): undefined reference to `globalconsts_mp_empty_'

any ideas?

0 Kudos
7 Replies
Ron_Green
Moderator
1,051 Views

In compiling the module source file, you need the "-c" option:

ifort -c mymodule.f90

Then you need the .mod AND the .o file created from the above. The .mod file you can think of as having all the procedure/data declarations - the actual code needed is in the .o file.

ron
0 Kudos
merrittr
Beginner
1,051 Views
Hey Thanks Ron

using the -c option did indeed give me .mod and .o files

root@rob-laptop:/home/rob/CreviceCorrSimCode/mods# ifort -c *.f90
root@rob-laptop:/home/rob/CreviceCorrSimCode/mods# ls
d2u.sh datatypes.mod GlobalConsts.f90 GlobalConsts.o globalvars.mod
DataTypes.f90 DataTypes.o globalconsts.mod GlobalVars.f90 GlobalVars.o


so I copied those up one level to my source directory ands tried again and got the same messages . Could it be related to the upcase characters in the .o files name

globalvars.mod VS GlobalVars.o



0 Kudos
merrittr
Beginner
1,051 Views
I also tried -module and -I for include path both with no luck



ifort -module ./ -I /home/rob/CreviceCorrSimCode -assume protect_parens *.f*
0 Kudos
Steven_L_Intel1
Employee
1,051 Views
First, the case of the module name is not important. As you'll see, the compiler creates the .mod file with a downcased filename always and looks for it there.

I think you have a common confusion about the way modules work. As you saw, when you compile a module you get a .mod and a .o. The .mod is read by the compiler when you have a USE statement. The .o is used by the linker and has the same name as the source file. The .o must be named when you link, otherwise you will get undefined references as you did.

When compiling and linking on a single command, then there's a single .o and no problem. If you use -c to separately compile module files, then you have to find a way to present those objects to the linker. You can either name them individually on the ifort command doing the linking, or insert them into a library (.a) and name that when you link. It is not sufficient to specify the path to the .o files when linking - you have to give the linker the file name(s).
0 Kudos
merrittr
Beginner
1,051 Views
thanks Doc.

That was the last peice in the puzzle

ifort -assume protect_parens *.f* modules.o

did the trick (I consolodate the 3 modules into one f90->.o)
0 Kudos
luis-cordova
Beginner
1,051 Views
I found you can do:

ifort file.f90 *.obj

This above will do great when you have a bunch of object files.

However, I am having the following error now:

which is related to not being able to use IMSL

fatal error LNK1104: cannot open file 'smaths.lib

any help???

0 Kudos
Steven_L_Intel1
Employee
1,051 Views
Do you have such a library? Have you specified -L so that the linker can find it? We don't provide IMSL with the Linux and Mac compilers, so if you have purchased it separately you should read the IMSL documentation for tips on use.
0 Kudos
Reply