[英]gfortran compile object file error crt1.o: In function `_start':
我已經編譯了一個fortran文件並創建了一個目標文件,之后我嘗試執行該目標文件但出現錯誤。操作系統是Ubuntu,錯誤如下:
編譯源文件
gfortran -O3 reader.f iotools.c -o reader.x
執行目標文件
gfortran reader.o
和錯誤
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:在函數
_start': (.text+0x20): undefined reference to
main的_start': (.text+0x20): undefined reference to
'reader.o:在函數MAIN__': fort77-2624-1.c:(.text+0xf): undefined reference to
ireadc_的MAIN__': fort77-2624-1.c:(.text+0xf): undefined reference to
fort77-2624-1.c :(。text + 0x278):對s_wsle' fort77-2624-1.c:(.text+0x291): undefined reference to
未定義引用s_wsle' fort77-2624-1.c:(.text+0x291): undefined reference to
do_lio'的s_wsle' fort77-2624-1.c:(.text+0x291): undefined reference to
fort77-2624-1.c :(。text + 0x2aa):對do_lio' fort77-2624-1.c:(.text+0x2c3): undefined reference to
未定義引用do_lio' fort77-2624-1.c:(.text+0x2c3): undefined reference to
do_lio的do_lio' fort77-2624-1.c:(.text+0x2c3): undefined reference to
fort77-2624-1.c :(。text + 0x2c8):未定義對e_wsle的引用collect2:錯誤:ld返回了1退出狀態
reader.f文件
ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
C Basic fortran (and c tools) code to read fMRI images
C Compile linux:g77 -O3 reader.f iotools.c -o reader.x
c In Cygwin compile as : (to prevent max memory bug)
c g77 -o reader.x -Wl,--stack,8388608 reader.f iotools.c
c Execute: reader.x < imagename.img
c where "imagename.img" is a huge image fmri file
c------------------------------------------------------
c Standard output: the full correlation matrix
c------------------------------------------------------
parameter(maxsites=147456,maxtime=400,mintime=1)
real a(maxsites*maxtime), b(maxsites*maxtime)
real*8 ax, sxx(maxsites), sxy, r
integer iflag(maxsites)
c.... Read image file into a
i=ireadc(a,4*maxsites*maxtime)
do ix=1, maxsites
do it=1, maxtime
b((ix-1)*maxtime+ it) = a((it-1)*maxsites + ix)
enddo
enddo
do ix=1, maxsites
iflag(ix)=0
ax=0.d0
sxx(ix)=0.d0
do it=mintime, maxtime
ax=ax + dble(b((ix-1)*maxtime + it))
enddo
ax=ax/dfloat(1+maxtime-mintime)! mean activity for this voxel
if(ax.gt.7000.d0.and.ax.lt.14000) then
iflag(ix)=1 ! flag the usefull voxels
do it=mintime, maxtime
ic=(ix-1)*maxtime + it
b(ic) = b(ic) - ax
sxx(ix) = sxx(ix) + dble(b(ic)*b(ic))
enddo
endif
enddo
c--------------------------------------------------------------
do l1=1, maxsites-1
if(iflag(l1).eq.1) then
do l2=l1+1, maxsites
if(iflag(l2).eq.1) then
sxy=0.d0
do it=mintime, maxtime
ic1 = (l1-1)*maxtime + it
ic2 = (l2-1)*maxtime + it
sxy = sxy + dble(b(ic1)*b(ic2))
enddo
r=sxy/dsqrt(sxx(l1)*sxx(l2))!linear l1-l2 correlation
write(*,*) l1,l2,r
endif
enddo
endif
enddo
end
您當然不執行對象.o文件。 您鏈接它以創建一個可執行文件。
但是請注意,您沒有創建reader.o
文件, reader.x
在以下位置創建了reader.x
文件:
gfortran -O3 reader.f iotools.c -o reader.x
使用此命令,應創建一個可執行文件reader.x
,您應該能夠執行它。 沒有第二個gfortran
命令。
要么
您可以分兩步完成。 首先編譯然后鏈接
gfortran -c -O3 reader.f iotools.c -o reader.o
gfortran reader.o
在這種情況下,第二個命令將創建一個名為a.out
的可執行文件。
兩種方式都是可能的。
這些都是絕對的基礎知識,在嘗試更多內容之前,請先進行一些研究。 閱讀教程,在其中的問題中搜索。 這里有很多非常相似的問題。 我在這里回答只是為了消除您的特定困惑,而有些重復可能並不能直接消除您的困惑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.