Results 1 to 5 of 5

Thread: Start up gcc fortran, problem with main

  1. #1
    creiners NNTP User

    Question 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

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,775

    Default Re: Start up gcc fortran, problem with main

    You say that "other codes produce the same error message". Does that mean that the a more simplyfied program like:
    Code:
          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.
    Henk van Velden

  3. #3
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: Start up gcc fortran, problem with main

    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.

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,775

    Default Re: Start up gcc fortran, problem with main

    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.
    Henk van Velden

  5. #5
    creiners NNTP User

    Thumbs up Re: Start up gcc fortran, problem with main

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •