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

Linking multiple main programs in one solution

Sudarshan_R_
Beginner
1,488 Views

Hello,

I am working on recompiling a really old fortran code into a 32 bit application. It has multiple 

subroutines, multiple main programs and uses many text files as reference for data. I am not familiar on 

how to recompile them.

For the sake of simplicity, lets assume the following:

Main Programs: MAIN.FOR, A.FOR and B.FOR

Subroutines: SUB1.FOR, SUB2.FOR

Data Files: FILE1, FILE2

The MAKEFILE in the old folder reads like this:

***************************************************************

.SUFFIXES: .for

.for.obj:

 fl /Gt9 $(fflags) >>prog.log

all: log prog.exe

log: del prog.log

prog.exe: MAIN.obj \

 SUB1.obj \

 SUB2.obj \

 A.obj \

 B.obj

 \makefile

 link @prog.rsp >>prog.log

A: A.obj

 link @A.rsp >>prog.log

B: B.obj

 link @B.rsp >>prog.log

*********************************************************************

To do this in visual fortran, I made three different projects under one solution and made project 

PROG (startup project containing MAIN.FOR and subroutines) dependent on project A(with A.FOR and 

subroutines) and project B(with B.FOR and subroutines). I included FILE1 and FILE2 in solution items 

folder and built the solution. However, this doesn't seem to achieve the required objective of linking the 

A and B with MAIN. I am relatively new to VS and would be so grateful if anybody could help me with 

this situation.

0 Kudos
6 Replies
ZlamalJakub
New Contributor III
1,488 Views

Create only one project with all *. for files included.

Lines

prog.exe: MAIN.obj \

 SUB1.obj \

 SUB2.obj \

 A.obj \

 B.obj

in makefile mean that prog.exe depends on compiled MAIN, SUB1, SUB2, A and B source files.

0 Kudos
Sudarshan_R_
Beginner
1,488 Views

That wouldn't work and i would get an error like this

error LNK2005: _MAIN__ already defined in A.obj

error LNK2005: _MAIN__ already defined in B.obj

I have provided the makefile of the old code so that you could get an idea of the order/technique of compilation. I dont want to make another makefile. I would prefer to compile using visual studio.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,488 Views

On your old platform, how did execution flow pass from MAIN to A and B?

If via CALL, then you wil be required to change "PROGRAM" in A and B to "SUBROUTINE" (without arguments), and if END contained "END PROGRAM" change to "END SUBROUTINE".

If you were on a really old system, then MAIN, A, B would look like a card stack, where A runs after MAIN and B runs after A. For this you would likely write a batch file

: YourBatchFile.bat
MAIN
A
B

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
1,488 Views

I suspect that these old sources were actually multiple programs that shared some sources. Multiple main programs don't work in any Fortran implementation I have known over 35 years.

0 Kudos
TimP
Honored Contributor III
1,488 Views

As Steve said, multiple main programs never have been allowed to link together.  However, various typos when resurrecting old code may cause the compiler to see multiple main programs.

0 Kudos
Sudarshan_R_
Beginner
1,488 Views

Thank you for your replies. I had earlier misunderstood the structure of the code. It basically creates multiple applications utilizing the same subroutines.

0 Kudos
Reply