Linking multiple main programs in one solution

Linking multiple main programs in one solution


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:




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

all: log prog.exe

log: del prog.log

prog.exe: MAIN.obj \

 SUB1.obj \

 SUB2.obj \

 A.obj \



 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.

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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


prog.exe: MAIN.obj \

 SUB1.obj \

 SUB2.obj \

 A.obj \


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

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.

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

Jim Dempsey

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.

Retired 12/31/2016

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.

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today