gfortran 编译目标文件错误crt1.o:在函数“_start”中:

gfortran compile object file error crt1.o: In function `_start':

我已经编译了一个 Fortran 文件和一个目标文件 created.After,我试图执行目标文件但是错误 appears.The OS 是 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: In function _start': (.text+0x20): undefined reference tomain' reader.o: In function MAIN__': fort77-2624-1.c:(.text+0xf): undefined reference toireadc_' fort77-2624-1.c:(.text+0x278): undefined reference to s_wsle' fort77-2624-1.c:(.text+0x291): undefined reference todo_lio' fort77-2624-1.c:(.text+0x2aa): undefined reference to do_lio' fort77-2624-1.c:(.text+0x2c3): undefined reference todo_lio' fort77-2624-1.c:(.text+0x2c8): undefined reference to `e_wsle' collect2: error: ld returned 1 exit status

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 文件。你link它来创建一个可执行文件。

但请注意,您没有创建 reader.o 文件,而是在以下位置创建了一个 reader.x 文件:

gfortran -O3 reader.f iotools.c -o reader.x

使用此命令应该会创建一个可执行文件 reader.x,您应该能够执行它。没有第二个 gfortran 命令。

您可以分两步完成。先编译再link

gfortran -c -O3 reader.f iotools.c -o reader.o

gfortran reader.o

在这种情况下,第二个命令创建一个名为 a.out.

的可执行文件

两种方式都可以。

这些都是绝对的基础知识,请在尝试更多之前先做一些研究。阅读教程,在那里搜索问题。这里有很多非常相似的问题。我在这里回答只是为了清除您的特定混淆,这些混淆可能无法从某些重复项中直接清除。