如何找出使用的是哪个编译器:g77 或 gfortran

发布于 2024-07-09 07:05:56 字数 413 浏览 5 评论 0原文

我正在为一个私人项目编译库,该项目依赖于许多库。 具体来说,依赖项之一是使用 Fortran 编译的。 在某些情况下,我看到了使用 g77 编译的依赖项,在其他情况下,我看到了使用 gfortran 编译的依赖项。 然后,我的项目被 ./configure 链接到 -lg2c-lgfortran,但到目前为止我一直在这样做手。

如果可能,我如何通过查看依赖库(例如通过 nm 或其他实用程序?)找出所使用的编译器是否为 g77(以及那么我将在链接选项中使用 -lg2c)或 gfortran (然后我将使用 -lgfortran)?

提前致谢!

I'm compiling library for a private project, which depends on a number of libraries. Specifically one of the dependencies is compiled with Fortran. On some instances, I've seen the dependency compiled with g77, on others I've seen it compiled with gfortran. My project then is ./configure'd to link with either -lg2c or -lgfortran, but so far I've been doing it by hand.

If it is possible, how can I find out, from looking into the dependent library (via e.g. nm or some other utility?), whether the used compiler was g77 (and then I'll use -lg2c in my link options) or gfortran (and then I'll use -lgfortran)?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月蹉跎了容颜 2024-07-16 07:05:56
nm filename | fgrep ' __g77'

如果使用 g77 将给出结果,同时

nm filename | fgrep '@@GFORTRAN'

如果使用 gfortran 将给出结果。

nm filename | fgrep ' __g77'

will give results if g77 was used, meanwhile

nm filename | fgrep '@@GFORTRAN'

will give results if gfortran is used.

乜一 2024-07-16 07:05:56

您需要在 nm filename 的输出中 grep 查找某些内容,以指示是否使用了 g77 还是 gfortran。 在大多数情况下,如果库至少在一处进行输入输出,它将调用 libg2c 或 libgfortran,并且您会注意到其中有一个带有 g77 的符号,或者 <代码>gfortran。 因此,最好的选择是使用 grep:

nm filename | grep _g77_
nm filename | grep _gfortran_

两个注意事项:

  1. 按照 geocar 的建议对 @@GFORTRAN 进行 Grepping 并不可靠:它只能在支持库版本控制的平台上工作,其中包括例如 linux,但是不是 Windows 或 Mac 操作系统。
  2. 某些编译代码仍然有可能调用绝对不支持的库函数(例如,如果它所做的只是简单的算术并且没有输入输出)。 在这种情况下,除非使用调试选项进行编译,否则无法判断哪个编译器输出它。

You need to grep for something, in the output of nm filename, that indicates whether g77 or gfortran was used. In most cases, if the library does at least input-output in one place, it will call libg2c or libgfortran and you will notice a symbol with g77 in it, or gfortran. So, your best bet is to use grep:

nm filename | grep _g77_
nm filename | grep _gfortran_

Two notes:

  1. Grepping for @@GFORTRAN as geocar suggested is not reliable: it will only work on platforms where library-versioning is supported, which includes e.g. linux but not Windows or Mac OS.
  2. It is still possible that some compiled code calls absolutely no support library function (if all it does is simple arithmetic and has not input-output, e.g.). In that case, unless it's compiled with debugging options, it's impossible to tell which compiler output it.
天涯离梦残月幽梦 2024-07-16 07:05:56

您也许可以通过使用 nm 并查看编译的代码是否使用其中一个或另一个的函数来弄清楚,但这确实是一种黑客行为。 您也许可以根据可用的库来确定它(例如,如果没有可用的 libg2c,则它不是 g77),但如果两者都可用,您仍然会有些模糊。 如果您可以自己构建依赖项,那么您可以使用构建过程的一部分以某种方式告诉另一部分(变量、文件等)您使用了哪一个。

You might be able to figure it out by using nm, and seeing if the compiled code uses functions from one or the other, but that's quite a hack. You may be able to figure it out based on which library is available (if there's no libg2c available, then it wasn't g77, for example), but then you still have some ambiguity if both are available. If you can build the dependency yourself, then you can use have one part of your build process tell another part somehow (variable, file, etc.) which one you used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文