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

Problem in including a fortran file into another one

Ahmad_Falahatpisheh
2,280 Views
Hi All,

I have a main.F90 fortran code which needs to use some functions in another code named supp.F90 (the first line of supp.F90 has INTERFACE statement). supp.F90 is provided by a third party program by which I can create data files readable by that program. I have put the file in the main code by INCLUDE statement. But when I run the command IFORT main.F90 but it does not recognize the functions which are in supp.90. I also used Parallel Studio XE but I get the same error although I put supp.F90 in header files. The error is:

error LNK2019: unresolved external symbol ...

Could someone help me how to compile this in both methods (command prompt and parallel studio)?

Thanks.
0 Kudos
1 Solution
Steven_L_Intel1
Employee
2,280 Views
Drop the /INCLUDE:"C:\PROG\BIN" - it doesn't do anything for you. Try this:

ifort main.f90 C:\PROG\BIN\SUPPIO.LIB

And if that doesn't work, show me the output of:

dir C:\PROG\BIN

View solution in original post

0 Kudos
12 Replies
Arjen_Markus
Honored Contributor I
2,280 Views
It is the link step that is failing, not the compile step.

Are the symbols the linker complains about names of subroutines and functions that you find in supp.f90 or
did you forget to add a library to the link step?

Regards,

Arjen
0 Kudos
Ahmad_Falahatpisheh
2,280 Views
Yes, all the unresolved external symbols are in supp.90. What do you think the problem is?

Thanks,
Ahmad
0 Kudos
mecej4
Honored Contributor III
2,280 Views
You have left us guessing as to

(i) at what point of main.f90 is the text in file supp.f90 included?

(ii) how did you compile and link your application?
0 Kudos
Ahmad_Falahatpisheh
2,280 Views
The main program has the following structure. For simplicity, I didn't put functions arguments.

program main
call myfunc1()
contains

subroutine myfunc1()
include 'supp.f90'
r = supp_fun1()
end subroutine
myfunc1

end program
main

supp.90 file:
INTERFACE
INTEGER(4) FUNCTION supp_fun1 &
(Title, &
Variables, &
FName, &
ScratchDir, &
FileType, &
Debug, &
VIsDouble)
!MS$ATTRIBUTES STDCALL :: supp_fun1
!MS$ATTRIBUTES REFERENCE :: Title,Variables,FName
!MS$ATTRIBUTES REFERENCE :: ScratchDir,FileType,Debug,VIsDouble
CHARACTER(LEN=*) Title
CHARACTER(LEN=*) Variables
CHARACTER(LEN=*) FName
CHARACTER(LEN=*) ScratchDir
INTEGER(4) FileType
INTEGER(4) Debug
INTEGER(4) VIsDouble
END FUNCTION supp_fun1

Regarding the second question I used both command line IFORT MAIN.F90 and Parallel Studio to build it. In the studio I add main.f90 in the source file and build it by default switches.

Also the following is the note the third party program gave for using supp.90. Hope it helps.
File supp.f90, located in the include folder in your installation, contain Fortran-90 interfaces for all SUPPIO routines and several compiler-specific directives (the !MS$ATTRIBUTES lines). These direct Visual Fortran to use STDCALL calling conventions with by-reference parameter passing. Include the appropriate file in any of your subroutines that call SUPPIO routines. The file was developed for Intel Visual Fortran version 9. (I am using IVF compiler XE).
Users of other compilers may need to adjust the Fortran settings or add other compiler directives to achieve the same effect. In particular, Fortran strings must be NULL-terminated and passed without a length argument.

Thanks.
0 Kudos
IanH
Honored Contributor II
2,280 Views
The interfaces in the included file (supp.f90) that you posted only tell the compiler what the calls to the routines should look like - the number and type of arguments that the procedures take, the return type of functions, etc (INTERFACE blocks tell the compiler what the interface is for a particular procedure).

The actual code for the routines is somewhere else. As other poster have already guessed, that's probably in a library (*.lib) that you need to include in the link step for your program. The notes for the third party "program" may describe it. On the command line you would normally just include the name of the library file after your fortran source code files. Within Visual Studio you set the Linker > Input > Additional Dependencies property for your project to include the library name.

(Parallel studio is the name of an Intel product bundle that contains the fortran compiler. The graphical user interface that is bundled with the Intel product you can use to access that compiler is actually a Microsoft program called "Visual Studio".)
0 Kudos
Ahmad_Falahatpisheh
2,280 Views
Thanks for your great explanation. I am converging to the solution of my problem. I have found the library name. I would be thankful if you could tell me why I don't get the code built. I use the following switches:

ifort main.f90 /include:"C:\prog\bin" suppio.lib

LINK : fatal error LNK1181: cannot open input file 'suppio.lib'
is the only error I get.
0 Kudos
IanH
Honored Contributor II
2,280 Views
The linker cannot find the file suppio.lib. Where is it on your system? Is it in one of the directories that the linker has been configured to search? When you find it perhaps specify its full path on the ifort command line - something like:

ifort /main.f90 /include:"C:\prog\bin" "C:\some directory\suppio.lib"

If you had searched the documentation (or even just used google) for "LNK1181" you probably could have worked this out yourself.
0 Kudos
Ahmad_Falahatpisheh
2,280 Views
Thanks for your comment. I had done what you suggested but it didn't work for me. Even specifying the full path does not solve the problem. It's strange. I would appreciate any other suggestion.

LINK : fatal error LNK1181: cannot open input file 'c:\prog\bin\suppio.lib'
0 Kudos
Steven_L_Intel1
Employee
2,280 Views
Is that full path where the library actually is located? Please show us the command line you are using and, if possible, attach suppio.lib to a reply here (see instructions in my signature below.) It could be that this is not a link library.
0 Kudos
Steven_L_Intel1
Employee
2,280 Views
Please show the command line you are using from a session where it failed. Please also include the error message output.
0 Kudos
Ahmad_Falahatpisheh
2,280 Views
IFORT MAIN.F90 /INCLUDE:"C:\PROG\BIN" "C:\PROG\BIN\SUPPIO.LIB"

LINK : fatal error LNK1181: cannot open input file 'c:\prog\bin\suppio.lib'
0 Kudos
Steven_L_Intel1
Employee
2,281 Views
Drop the /INCLUDE:"C:\PROG\BIN" - it doesn't do anything for you. Try this:

ifort main.f90 C:\PROG\BIN\SUPPIO.LIB

And if that doesn't work, show me the output of:

dir C:\PROG\BIN
0 Kudos
Reply