代码之家  ›  专栏  ›  技术社区  ›  Alessandro Peca

用Fortran从文件中读取列,g++给出了“未定义的符号:“\uu gfortran\u set\u args”`

  •  1
  • Alessandro Peca  · 技术社区  · 7 年前

    我试图用Fortran从输入文件中读取列,用于其他计算。

     Undefined symbols for architecture x86_64:
      "__gfortran_set_args", referenced from:
          _main in ccOO2MBV.o
      "__gfortran_set_options", referenced from:
          _main in ccOO2MBV.o
      "__gfortran_st_close", referenced from:
          _MAIN__ in ccOO2MBV.o
      "__gfortran_st_open", referenced from:
          _MAIN__ in ccOO2MBV.o
      "__gfortran_st_read", referenced from:
          _MAIN__ in ccOO2MBV.o
      "__gfortran_st_read_done", referenced from:
          _MAIN__ in ccOO2MBV.o
      "__gfortran_transfer_real", referenced from:
          _MAIN__ in ccOO2MBV.o
    ld: symbol(s) not found for architecture x86_64
    collect2: error: ld returned 1 exit status
    

    我哪里错了?代码如下:

    program columns
    
      INTEGER,SAVE :: lun
      INTEGER, PARAMETER :: ARRAYLEN=1440
      CHARACTER :: filename
      DOUBLE PRECISION, DIMENSION (1044) :: X_halo, Y_halo, Z_halo
      INTEGER :: i
    
      lun=1
      filename = 'xyz.dat'
    
      OPEN (1, FILE='xyz.dat',STATUS='old', ACTION='read', iostat=istat)
    
        do i=1,1440
           READ (1, iostat=istat) X_halo(i), Y_halo(i), Z_halo(i)
        end do
    
      CLOSE (1)
    
    end program columns
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Steve    7 年前

    正如@d_1999所指出的那样,编译器应该是 gfortran g++ .

    READ 指定,此处为

    READ (1, *, iostat=istat) X_halo(i), Y_halo(i), Z_halo(i)
    

    program columns
      ! Add implicit none to catch that `istat` is not declared
      IMPLICIT NONE
    
      INTEGER,SAVE :: lun
      INTEGER, PARAMETER :: ARRAYLEN=1440
      ! Make `filename` bigger than a single character
      CHARACTER(120) :: filename
      ! can add `ARRAYLEN` here
      DOUBLE PRECISION, DIMENSION (ARRAYLEN) :: X_halo, Y_halo, Z_halo
      ! Have added `istat` here
      INTEGER :: i, istat
    
      lun=1
      filename = 'xyz.dat'
      ! Have replaced `xyz.dat` with `filename` and using a higher `UNIT` number
      OPEN (UNIT=10, FILE=filename, STATUS='old', ACTION='read', IOSTAT=istat)
    
        ! Using `ARRAYLEN` for the loop.
        ! I've also capitalised the keywords (matter of preference)
        DO i=1,ARRAYLEN
           ! And the important format specifier
           READ (10, *, iostat=istat) X_halo(i), Y_halo(i), Z_halo(i)
        END DO
    
      CLOSE (10)
    
    end program columns
    

    其中一些问题(例如。 filename 没有足够大)会被用 -Wall

    gfortran -Wall columns.f90 -o columns.exe