0

I have compiled a fortran file and an object file created.After that i tried to execute the object file but an error appears.The OS is Ubuntu and the error is below:

To compile the source file

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

To execute object file

gfortran reader.o

And the error

/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 file

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
8
  • The source file and the commands where given from the professor.So i should be gfortran -c -O3 reader.f iotools.c -o reader.x ? Commented Oct 29, 2017 at 10:35
  • That does not really matter, clearly they are wrong or you copied them wrong. Is there a main program in your code? Or a main function? How does the code look like? Commented Oct 29, 2017 at 10:36
  • Yes, you should have the -c flag there AND -o reader.o. OR you should skip the second command. Commented Oct 29, 2017 at 10:41
  • gfortran -c reader.o ? Commented Oct 29, 2017 at 10:44
  • NO, not at all. Commented Oct 29, 2017 at 10:45

1 Answer 1

1

You certainly do not execute an object .o file. You link it to create an executable file.

But Notice you do not create the reader.o file, you create a reader.x file in:

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

With this command an executable file reader.x should be created and you should be able to execute it. There is no second gfortran command.

OR

You can do it in two steps. First compile and then link

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

gfortran reader.o

In this case the second command creates an executable file called a.out.

Both ways are possible.

These are absolute basics, please do some study first before attempting more. Read a tutorial, search among the questions there. There are many very similar questions here. I answered here just to clear your specific confusions which might not be that directly clear from some duplicates.

Sign up to request clarification or add additional context in comments.

4 Comments

Execute: reader.x < imagename.img where "imagename.img" is a huge image fmri file. How i will do that?
By writing reader.x < imagename.img at the command line. Have you used Linux before? These are absolute basics. There is no place to teach you those here. You have to study the basics first, really.
I have executed reader.x < imgNAme.img but error appears reader.x: command not found
You need ./reader.x. Make sure you are in the right directory and reader.x exists. This is my last comment. You must study Linux basics first. Take a tutorial on youtube or read something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.