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

Failure of compiling fortran codes: duplicate symbol for architecture x86_64

Tan__Fu
Beginner
1,589 Views

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
mecej4
Honored Contributor III
1,589 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
TimP
Honored Contributor III
1,589 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
Tan__Fu
Beginner
1,589 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
Tan__Fu
Beginner
1,589 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
Reply