Why Am I Experiencing Compilation Errors with My Fortran Code?

  • Context: Fortran 
  • Thread starter Thread starter shenie
  • Start date Start date
  • Tags Tags
    Compiler Fortran
Click For Summary
SUMMARY

The discussion centers on compilation errors encountered while compiling Fortran code using the Absoft Fortran Compiler 10.1. The user experiences linker errors due to multiple definitions of the symbol _MAIN_ caused by compiling both simple.f95 and sample1.f90, which each contain a main program. The solution involves modifying the project file to ensure only one main program is compiled, thus resolving the linker conflict.

PREREQUISITES
  • Understanding of Fortran programming language syntax and structure
  • Familiarity with the Absoft Fortran Compiler 10.1
  • Knowledge of linking and compilation processes in programming
  • Basic experience with project file configurations in development environments
NEXT STEPS
  • Review Fortran project file settings to prevent multiple main program compilations
  • Learn about the Fortran linking process and how to resolve linker errors
  • Explore the use of modules in Fortran to manage code organization
  • Investigate best practices for error handling in Fortran file I/O operations
USEFUL FOR

This discussion is beneficial for novice Fortran programmers, software developers using the Absoft Fortran Compiler, and anyone troubleshooting compilation and linking issues in Fortran projects.

shenie
Messages
3
Reaction score
0
I am having trouble compiling code. Here's my code:

PROGRAM Sample1

IMPLICIT NONE
! Variables and constants
INTEGER, PARAMETER :: n=1000, m=10
INTEGER :: i
REAL, DIMENSION (1: n) :: x
REAL, DIMENSION (1:100, 1:m) :: y
REAL, DIMENSION (1: m):: colavg
INTEGER :: filestat, IO_stat_num


! Open file and Check for error

OPEN( UNIT=10, FILE= 'Data1.txt', IOSTAT=filestat, STATUS='OLD')

IF (filestat>0) THEN
PRINT *, 'Error opening file. Error Code: ', filestat
STOP
ENDIF

DO i=1, n

READ (UNIT=10, FMT=101, IOSTAT=IO_stat_num) x(i)
101 FORMAT (2F8.3)

IF (IO_stat_num == 0) THEN
CYCLE
ELSEIF (IO_stat_num == -1) THEN
PRINT *,'EOF at line ', i
EXIT

ELSEIF(IO_stat_num > 0) THEN
PRINT *,'Non numeric data at line ', i
EXIT
ENDIF
ENDDO
CLOSE(UNIT=10)
! call sorting routine from book

CALL shell (n,x)

! Create ten averaged bins

y = RESHAPE(x,(/100,10/))
colavg = sum( y, dim=1)
colavg = colavg/100

OPEN(UNIT=20, FILE='Bins1', STATUS='NEW')

WRITE (UNIT=20) colavg

CLOSE (UNIT=20)

END PROGRAM Sample1

SUBROUTINE shell(n,a)

INTEGER n
REAL a(n)
INTEGER i,j, inc
REAL v

inc=1
1 inc=3*inc+1
if(inc.le.n) goto 1
2 CONTINUE
inc =inc/3
DO i = inc+1, n
v= a(i)
j=i
3 IF (a(j-inc).gt.v) THEN
a(j)=a(j-inc)
j=j-inc
IF (j.le.inc) GOTO 4
GOTO 3
ENDIF
4 a(j)=v

ENDDO

if(inc.gt.1) GOTO 2

RETURN
END


Error reads:

Begin scan
amakedepend "@/Users/sbraswell/Release/mkdep_F95"
Scan completed
Begin build
f95 -c -nowdir -mrwe -m32 -O2 -o "./Release/simple.o" "../../Applications/Absoft10.1/examples/simple.f95"
f95 -c -nowdir -mrwe -m32 -O2 -o "./Release/sample1.o" "Desktop/sample1.f90"
f95 -lmrwe -framework Carbon -laf90math -lafio_carbon -lmrwe -lafio_carbon -lamisc -labsoftmain_mrwe -laf77math -lm -lmv -osxtarget=10.4 -m32 -O2 "./Release/simple.o" "./Release/sample1.o" -o "./sample.app/Contents/MacOS/sample"
/usr/bin/ld: multiple definitions of symbol ABSOFT_IO_INITIALIZE
./Release/simple.o definition of ABSOFT_IO_INITIALIZE in section (__DATA,__data)
./Release/sample1.o definition of ABSOFT_IO_INITIALIZE in section (__DATA,__data)
/usr/bin/ld: multiple definitions of symbol _MAIN__
./Release/simple.o definition of _MAIN__ in section (__TEXT,__text)
./Release/sample1.o definition of _MAIN__ in section (__TEXT,__text)
collect2: ld returned 1 exit status
Make:
*** Error code 256 from f95
link failed.
Build interrupted

PLEASE HELP
 
Technology news on Phys.org
It appears to be compiling two files: simple.f95 and sample1.f90.

Which gives it two _MAIN_ modules which the linker doesn't like.

Is there something wrong with your make or project file?
 
Thanks..I didn't realize it was trying to compile 2. My first time using fortran.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K