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

Multi- fortran files in one visual-studio project

yingwu
Beginner
1,242 Views
Hi,

I am a new one turning to Intel Fortran. I use Visual studio 2008 with IVF 11. I create a fortran project and add one and only one F90 code to the project. Everything is ok. However, when I try to more fortran F90 files to the project, I get the erroe message,

1>rpca2.obj : error LNK2005: _MAIN__ already defined in fortranTest2.obj
1>Debug\Console1.exe : fatal error LNK1169: one or more multiply defined symbols found

So it seems there can be one and only one f90 file in the project. Could somebody help me with this? Thanks very much.
0 Kudos
5 Replies
TimP
Honored Contributor III
1,242 Views
Quoting - yingwu

1>rpca2.obj : error LNK2005: _MAIN__ already defined in fortranTest2.obj
1>DebugConsole1.exe : fatal error LNK1169: one or more multiply defined symbols found

So it seems there can be one and only one f90 file in the project.
Make that only one Fortran main program in a normal project. Errors are conceivable which could produce an unintended main program.
0 Kudos
yingwu
Beginner
1,242 Views
Quoting - tim18
Make that only one Fortran main program in a normal project. Errors are conceivable which could produce an unintended main program.

Hi, thanks for your so soon reply. Because I just switch to Fortran, so my questions may be silly. Could you give me more detail in how to Make that only one Fortran main program? You mean set one file as the main program? So what about other f90 files? Is there any example? Thanks very much for your help...

PS: the solution explorer is like this:




There are two F90 files.
0 Kudos
Steven_L_Intel1
Employee
1,242 Views

It does not matter how many source files you have. Each source file can have one or more "program units" in it, which can be a main program, subroutine, function, BLOCK DATA or module. However, in your entire application, there can be only one main program - a program unit beginning with PROGRAM or not beginning with SUBROUTINE, FUNCTION, MODULE or BLOCK DATA.

It looks as if both source files FortranTest2.f90 and rpca2.f90 both have main programs. If what you want is to have separate executables for these programs, each one has to be in its own project. You can have more than one project in a solution. Note that only one project in a solution is the "Startup project" - this is indicated by the project name in bold face text and is the one that will be used when you ask to run or debug the solution. You can change which project is the startup project by right clicking on the new one and selecting "Set as startup project".
0 Kudos
yingwu
Beginner
1,242 Views

It does not matter how many source files you have. Each source file can have one or more "program units" in it, which can be a main program, subroutine, function, BLOCK DATA or module. However, in your entire application, there can be only one main program - a program unit beginning with PROGRAM or not beginning with SUBROUTINE, FUNCTION, MODULE or BLOCK DATA.

It looks as if both source files FortranTest2.f90 and rpca2.f90 both have main programs. If what you want is to have separate executables for these programs, each one has to be in its own project. You can have more than one project in a solution. Note that only one project in a solution is the "Startup project" - this is indicated by the project name in bold face text and is the one that will be used when you ask to run or debug the solution. You can change which project is the startup project by right clicking on the new one and selecting "Set as startup project".
Hi Steve, thanks for your useful answer. So you mean there is only one f90 file beginning with PROGRAM, right? Yes, the two files in my project all start with 'PROGRAM', which is the reason I have the error. OK, now, I know I should put the two files in two projects (in one solution) repectively. It is just boring, because the size of the project folders become very much larger after the projects are compiled. Any suggestion?
0 Kudos
Steven_L_Intel1
Employee
1,242 Views

If you want to use projects, that's the way you have to do it. Only one main program per project. You don't have to have all the projects in a single solution - typically you would do that only if the projects were closely related. More common is to have a separate solution for each executable.
0 Kudos
Reply