Fortran Why Am I Experiencing Compilation Errors with My Fortran Code?

  • Thread starter Thread starter shenie
  • Start date Start date
  • Tags Tags
    Compiler Fortran
AI Thread Summary
The discussion centers around a compilation error encountered while trying to compile Fortran code. The user is attempting to compile two files, simple.f95 and sample1.f90, which both contain a main program. This results in multiple definitions of the symbol _MAIN__, causing the linker to fail. The user is advised that the issue stems from having two main modules in the project, which is not allowed. They are encouraged to check the make or project file to resolve the conflict. The user also shares their experience as a beginner in Fortran, indicating a learning curve in understanding project structure and compilation processes.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
5
Views
5K
Replies
3
Views
5K
Replies
6
Views
2K
Replies
16
Views
2K
Replies
8
Views
4K
Replies
10
Views
2K
Replies
2
Views
2K
Back
Top