问题
I am trying to execute give fortran code in Code::Blocks on Windows 8
program main
write (*,*) "hi"
stop
end
The error I am getting is
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_st_write'
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_transfer_character_write'
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_st_write_done'
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_stop_string'
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_set_args'
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_set_options'
=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===
I copy pasted the .f file in the folder of the compiler itself and executed the command
gfortran.exe hello.f
The output .exe file is successfully generated and executed. I am not sure if I have setup the compiler properly in C::B. What I might be missing?
UPDATE : As suggested by janneb, I added the linker library path so as to use libgfortran-3.dll. The file gets compiled successfully with the following build log :
mingw32-g++.exe -c G:\Study\Programs\bairstow.f -o G:\Study\Programs\bairstow.o
mingw32-g++.exe -o G:\Study\Programs\bairstow.exe G:\Study\Programs\bairstow.o "C:\Program Files (x86)\CodeBlocks\MinGW\bin\libgfortran-3.dll"
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
When I execute the file, after waiting for about 2 minutes, I get the following error: Have I made any mistake in linking the library file?
Hint : It has messed up with my GNU C Compiler also. Now even after unlinking the libgfortran-3.dll, I can't execute a simple helloWorld.c program.
回答1:
Based on the error message you're not linking the GFortran runtime library (libgfortran) when compiling via C::B. The gfortran.exe driver program automatically handles this, so most likely you're compiling with gcc.exe, which based on the file extension can invoke the Fortran compiler (f951), but doesn't do the linking stuff that gfortran.exe does.
Anyway, I have never used C::B nor gfortran on Windows, but hopefully the above explanation gives you a hint where to start looking.
回答2:
Open C::B IDE and Go to "Settings" and Select "GNU Fortran Compiler" From Selected Compiler and Clik the button "Set as default" and finally click "Ok"
回答3:
In my case I had to do an additional step. Go to Project->Build options-> select the GNU Fortran Compiler as well.
来源:https://stackoverflow.com/questions/26794543/unable-to-compile-f-fortran-file-in-codeblocks-13-12