0

I'm a new user of fortran. After installing mingw and g95, I try to run a simple hello_world.f90:

PROGRAM hello_world

PRINT *, 'Hello World! Welcome to FORTRAN!'

END

the compiling shows:

D:\fortran_test>Fortran>g95 hello_world.f90 -o hello_world.o
'Fortran' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

Then i tried following:

D:\fortran_test>g++ hello_world.f90
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dell\AppData\Local\Temp\ccXOhIRu.o:hello_world.f90:(.text+0x3b): undefined reference to `_gfortran_st_write'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dell\AppData\Local\Temp\ccXOhIRu.o:hello_world.f90:(.text+0x59): undefined reference to `_gfortran_transfer_character_write'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dell\AppData\Local\Temp\ccXOhIRu.o:hello_world.f90:(.text+0x67): undefined reference to `_gfortran_st_write_done'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dell\AppData\Local\Temp\ccXOhIRu.o:hello_world.f90:(.text+0x8a): undefined reference to `_gfortran_set_args'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Dell\AppData\Local\Temp\ccXOhIRu.o:hello_world.f90:(.text+0x9e): undefined reference to `_gfortran_set_options'
collect2.exe: error: ld returned 1 exit status

Could anyone help me out of this! Much appreciated!

Ian Bush
  • 6,996
  • 1
  • 21
  • 27
yangyang
  • 1
  • 1
  • 1
    Do you have gfortran installed with g++ ? If so, you could compile with `gfortran hello_world.f90`. – Pierre de Buyl Jul 31 '20 at 07:42
  • You should not link Fortran using the `g++` command but using the `gfortran` command. If linking using `g++` you need to link the Fortran runtime library `libgfortran` explicitly. If you do not have `libgfortran`, you cannot use `g++` to compile Fortran. – Vladimir F Героям слава Jul 31 '20 at 07:57
  • The first error is because you used `D:\fortran_test>Fortran>g95` and you should have used just `D:\fortran_test>g95` it is a simple typo not worthy of a separate answer. The error says that `Fortran` is not a name of a known command. – Vladimir F Героям слава Jul 31 '20 at 08:02

0 Answers0