Start up gcc fortran, problem with main

Hello all,

I tried to use fortran with gcc and Suse 10.3… The code of the first program is:

  PROGRAM MAIN
  INTEGER N, X
  EXTERNAL SUB1
  COMMON /GLOBALS/ N
  X = 0
  PRINT *, 'Enter number of repeats'
  READ (*,*) N
  CALL SUB1(X,SUB1)
  END

  SUBROUTINE SUB1(X,DUMSUB)
  INTEGER N, X
  EXTERNAL DUMSUB
  COMMON /GLOBALS/ N
  IF(X .LT. N)THEN
    X = X + 1
    PRINT *, 'x = ', X
    CALL DUMSUB(X,DUMSUB)
  END IF
  END

To compile the program, I put the following commands in the terminal window:

conrad@linux-jgw6:~/Fortran/First> gcc -Wall -c firsttry.f
conrad@linux-jgw6:~/Fortran/First> gcc firsttry.o -lgfortran
/usr/lib64/gcc/x86_64-suse-linux/4.2.1/…/…/…/…/lib64/crt1.o: In function _start': (.text+0x20): undefined reference to main’
collect2: ld returned 1 exit status

Possibly there is something wrong with the part ‘main’. I thing it doesn’t depend on the code above, because other codes produce the same error message.

Do you have any suggestions to solve this problem.
Thanks in advance.

Conrad

You say that “other codes produce the same error message”. Does that mean that the a more simplyfied program like:

      PROGRAM MAIN
      PRINT *,"HELLO WORLD"
      END

Gives the same error?

And what when you omit the PROGRAM statement? It isn’t a must after all.

Shouldn’t you be using gfortran to compile and link? If you use gcc, fortran specific startup objects are not linked in. The gcc command is meant for compiling and linking C, even though a lot of the compiler is shared with gfortran.

I think ken_yap is right (as usual). Not having compiled Fortran programs on Linux systems for a long time I wasn’t sure, but using gcc looked strange to me. So try ken_yaps’ suggestion first.

Hello together,

thanks for answering. The problem is solved. The package gcc-fortran was missing, so the command ‘gfortran’ doesn’t work.

After installing the package, it is possible to exchange the command gcc with gfortran.

Thanks a lot
Conrad