Compiling a Fortran Multi-Part Program

I am very new to Fortran and the entire Intel compilation (I use the Windows-based Intel compiler with the IMSL library without Visual Studio integration, therefore only on the command line).

The problem should be extremely simple: I have a Fortran program that I need to compile, which is stored as four different parts of the source code. The main program (and some subroutines) are stored in a code file called central.for, and there are also three files, let them call s1.for, s2.for and s3.for, each of which contains only one subroutine (lets call them sub1 -sub3) and no main program. The main program calls the routines stored in s1-s3, as well as in central.for.

The question is how to compile it:

When I try to compile central.for, it gives error LNK2019: unresolved external symbol _SUB1 referenced in function _MAIN__. Similarly, it gives the same message for SUB2 and SUB3.

When I try to compile s1.for-s3.for, it gives error LNK2019: unresolved external symbol _MAIN__ referenced in function _main

It seems obvious that I need to somehow connect them. However i have no idea how

+5
source share
2 answers

You need to compile program fragments without linking them first, and then connecting them all together. So your command line will look like this:

ifort /c s1.for
ifort /c s2.for
ifort /c s3.for
ifort /c central.for

/c /compile-only; /nolink . s1.o, s2.o, s3.o central.o . . , -

ifort /exe:central.exe central.o s1.o s2.o s3.o

.

, , fortran, , () central.for use s2. ( /c) s2 ; s2 s2.mod. s2.mod central.for. , , , .

+3

. . .lib ( ). , ( CALL MYLIBFUN())

.

0

All Articles