Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
99 Views

Failure of compiling fortran codes: duplicate symbol for architecture x86_64

Dear Expert Users,

 

I'm a Mac user with OS X EI Capitan 10.11.6. I am trying to compile four fortran codes (distr.f90, global.f90, toolbox.f90, main.f90) with intel fortran compiler 2017 by the following command:

ifort -c distr.f90

ifort -c global.f90

ifort -c toolbox.f90

ifort -c main.f90

ifort main.f90 global.f90 toolbox.f90 distr.f90 -o test.exe

However, I got the following error after the last command:

duplicate symbol _global._ in:
    /var/folders/4m/j48kkdrj63zcx3zxhxp6rf100000gn/T/iforto9DdFb.o
    /var/folders/4m/j48kkdrj63zcx3zxhxp6rf100000gn/T/ifort1RnV6O.o
ld: 1 duplicate symbol for architecture x86_64

Is there anything wrong with the process either the compiling codes or others?

I am in a hurry to finish a project. I appreciate your prompt help and support! Thank you very much in advance!

Best,

Fu

0 Kudos
4 Replies
Highlighted
Black Belt
99 Views

One obvious error that you committed is that you compiled each source file twice, once separately, and again the last command, which causes all the source files to be recompiled. You would save some time by replacing ".f90" by ".o" in the last command.

Is "global" a data item or a code item (meaning, the name of a subroutine or function)? You would have found out which source files contain declarations of "global" if you had used ".o" instead of ".f90" in the last command.

 

0 Kudos
Highlighted
Black Belt
99 Views

If you have more than one Fortran main program (f77 PROGRAM header or f66 implied header), that would cause a conflict in linking the multiple files.  f66 implied main program has been known to happen due to corruption of source file causing compiler to see a compilation unit with no PROGRAM, SUBROUTINE, or FUNCTION header.

0 Kudos
Highlighted
Beginner
99 Views

Thank you for suggestion of replacing ".f90" by ".o". Global is a module (code item). I realized that I mistakenly added "include "global.f90"" at the beginning of the main.f90 file, which caused me the error. After deleting it, it works perfectly. 

mecej4 wrote:

One obvious error that you committed is that you compiled each source file twice, once separately, and again the last command, which causes all the source files to be recompiled. You would save some time by replacing ".f90" by ".o" in the last command.

Is "global" a data item or a code item (meaning, the name of a subroutine or function)? You would have found out which source files contain declarations of "global" if you had used ".o" instead of ".f90" in the last command.

 

 

0 Kudos
Highlighted
Beginner
99 Views

Thank you for pointing out what the issue might be. I mistakenly added "include "global.f90"" at the beginning of the main.f90 file. After deleting it, I successfully complied all the main program file. 

Tim P. wrote:

If you have more than one Fortran main program (f77 PROGRAM header or f66 implied header), that would cause a conflict in linking the multiple files.  f66 implied main program has been known to happen due to corruption of source file causing compiler to see a compilation unit with no PROGRAM, SUBROUTINE, or FUNCTION header.

0 Kudos