- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have two source file with two programs, and one program file try to call a funciton in the other program file:
=====================================
$cat main.f90
program main
end program main
subroutine hello
print *,'Hello world!'
end subroutine hello
======================================
$cat test.f90
program test
call hello
end program test
$ifort -c test.f90
$ifort -c main.f90
$ifort test.o main.o -o test
duplicate symbol '_MAIN__' in:
test.o
main.o
Does someone know how to get ride of the this _MAIN__ error?
Thanks!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Remove "program main... end program main" from main.f90. Your test.f90 contains the main program, main.f90 contains only a subroutine (so your files are misnamed.) You are not allowed to have two main programs; it is fine (and typical) to have only a subroutine (or function) in a separate source file.
You can, of course, simply add the subroutine to the end of test.f90. When you start writing more complex programs you can have multiple subroutines and functions in a source file. (The difference is that a function returns a value while a subroutine does not.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much Steve for the solution.
I'm actually having several subroutines in main.f90. The main program in main.f90 called all the subroutines there.
I create another program in test.f90 and tried to call some of the subroutines in main.f90, which do not work and give this _MAIN__error.
Since the programs' name (main and test) are different, I have thought that ifort compiler should recognize there are two different programs the user want to build.
Anyhow, as you suggested, I will create file_1 contains the subroutines; file_2 contains the 1st program and file_3 contains the 2nd program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can build only one program at a time, which means one main program across all the source files.
![](/skins/images/7FC17B7B85029576C25F1E43CE255B51/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page