无法在代码块 13.12 中编译 .f(fortran 文件) [英] Unable to compile .f (fortran file) in codeblocks 13.12

查看:31
本文介绍了无法在代码块 13.12 中编译 .f(fortran 文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows 8 上的 Code::Blocks 中执行 give fortran 代码

I am trying to execute give fortran code in Code::Blocks on Windows 8

   program main
   write (*,*) "hi"
   stop
   end

我得到的错误是

G:StudyProgramsairstow.o:bairstow.f undefined reference to `_gfortran_st_write'
G:StudyProgramsairstow.o:bairstow.f undefined reference to `_gfortran_transfer_character_write'
G:StudyProgramsairstow.o:bairstow.f undefined reference to `_gfortran_st_write_done'
G:StudyProgramsairstow.o:bairstow.f undefined reference to `_gfortran_stop_string'
G:StudyProgramsairstow.o:bairstow.f undefined reference to `_gfortran_set_args'
G:StudyProgramsairstow.o:bairstow.f undefined reference to `_gfortran_set_options'
=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===

我将.f文件复制粘贴到编译器本身的文件夹中并执行命令

I copy pasted the .f file in the folder of the compiler itself and executed the command

gfortran.exe hello.f

输出 .exe 文件已成功生成并执行.我不确定我是否在 C::B 中正确设置了编译器.我可能会错过什么?

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?

更新:按照 janneb 的建议,我添加了链接器库路径以使用 libgfortran-3.dll.该文件使用以下构建日志成功编译:

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:StudyProgramsairstow.f -o G:StudyProgramsairstow.o
mingw32-g++.exe  -o G:StudyProgramsairstow.exe G:StudyProgramsairstow.o   "C:Program Files (x86)CodeBlocksMinGWinlibgfortran-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))

当我执行文件时,等待大约 2 分钟后,我收到以下错误:我在链接库文件时是否犯了任何错误?

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?

提示:我的 GNU C 编译器也搞砸了.现在即使取消链接 libgfortran-3.dll,我也无法执行简单的 helloWorld.c 程序.

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.

推荐答案

根据错误消息,您在通过 C::B 编译时没有链接 GFortran 运行时库 (libgfortran).gfortran.exe 驱动程序会自动处理这个问题,因此您很可能正在使用 gcc.exe 进行编译,它基于文件扩展名可以调用 Fortran 编译器 (f951),但不会执行 gfortran.exe 所做的链接工作.

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.

无论如何,我从未在 Windows 上使用过 C::B 或 gfortran,但希望上面的解释能够提示您从哪里开始寻找.

Anyway, I have never used C::B nor gfortran on Windows, but hopefully the above explanation gives you a hint where to start looking.

这篇关于无法在代码块 13.12 中编译 .f(fortran 文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆