【问题标题】:"Relocation truncated to fit" only with -static“重定位被截断以适应”仅使用 -static
【发布时间】:2015-10-20 18:24:22
【问题描述】:

我在 Windows 7 上使用来自 cygwin (x86_64) 的 gfortran 来编译来自 NASA 的一些旧的 fortran 代码。当我使用

gfortran cma.f -o cma.exe

代码可以编译并运行,但需要在同一文件夹中的以下四个库才能运行: cyggcc_s-seh-1.dll, cyggfortran-3.dll, cygquadmath-0.dll,和 cygwin1.dll

我想让它独立运行,所以我试过了

gfortran cma.f -static -o cma.exe

然后我得到几个“重定位被截断以适应:R_X86_64_PC32 针对未定义符号”的错误:

/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/libgfortran.a(write.o): In function `write_float':
/usr/src/debug/gcc-4.9.3-1/libgfortran/io/write_float.def:1300:(.text$write_float+0x15c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `quadmath_snprintf'
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/libgfortran.a(write.o): In function `determine_en_precision':
/usr/src/debug/gcc-4.9.3-1/libgfortran/io/write_float.def:1213:(.text$write_float+0x7cf): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `quadmath_snprintf'
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/libgfortran.a(write.o): In function `write_float':
/usr/src/debug/gcc-4.9.3-1/libgfortran/io/write_float.def:1300:(.text$write_float+0x84e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `quadmath_snprintf'
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/libgfortran.a(write.o): In function `output_float_FMT_G_16':
/usr/src/debug/gcc-4.9.3-1/libgfortran/io/write_float.def:1140:(.text$write_float+0xf22): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `quadmath_snprintf'
/usr/src/debug/gcc-4.9.3-1/libgfortran/io/write_float.def:1140:(.text$write_float+0x1781): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `quadmath_snprintf'
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/libgfortran.a(read.o): In function `_gfortrani_convert_real':
/usr/src/debug/gcc-4.9.3-1/libgfortran/io/read.c:175:(.text$_gfortrani_convert_real+0x72): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `strtoflt128'
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/libgfortran.a(read.o): In function `_gfortrani_convert_infnan':
/usr/src/debug/gcc-4.9.3-1/libgfortran/io/read.c:251:(.text$_gfortrani_convert_infnan+0x53): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `strtoflt128'
collect2: error: ld returned 1 exit status

我是从源代码编译的新手,但我做过一些编程(主要是在 matlab/octave 中)。我不知道 Fortran,代码长 4418 行,并且做了一些复杂的热力学。所以修改代码对我来说不是一个很好的选择。

我还知道它可以在带有 MS Visual Studio 的 32 位 Windows 控制台应用程序中编译,使用 Intel Fortran composer XE2013,更新 5,编译器具有以下选项:132 列,32 位发布版本,并且没有运行时数组边界检查。但我没有英特尔编译器。

所以它应该只是用于 gfortran 的编译器选项的问题。我已经尝试了很多不同的标志,但到目前为止没有一个成功。那么如何让exe独立运行”?

有一些类似的问题,但是这些解决方案似乎涉及代码的编写方式。我无法更改代码,因此我需要一个涉及如何编译代码的解决方案。

【问题讨论】:

  • 你安装了静态版的 libquadmath 吗?
  • 如何判断我是否安装了静态版本的 libquadmath?我安装了这些文件: libquadmath.a libquadmath.info.gz libquadmath.dll.a libquadmath0.lst.gz quadmath.h quadmath_weak.h
  • 我查看了what-does this GCC... 和提供的链接。答案解释了发生了什么,但如果代码很好并且问题在于它的编译方式,则不解释如何修复它。它表明 gfortran 无法识别“-mmodel”,类似的“-mcmodel=large”不会改变结果。还提到了“movabs 指令”,我不知道他在说什么,搜索也没有出现太多。也许我错过了什么?我对此很陌生,即星期一。
  • 是否可以访问英特尔编译器?一些代码(尤其是旧代码,在我有限的经验中)使用了许多特定于编译器的函数,您可能很难全部更改它们。如果您知道它可以使用 Intel 编译,您可以使用 Intel 静态构建它吗?并不是说我认为您当前的问题一定与特定于编译器的函数有关。

标签: windows-7 fortran cygwin gfortran


【解决方案1】:

我认为您必须在 cygwin64 中删除“-static”。 AFAIK,在 cygwin64 包中只提供了 gfortran 的共享库版本。

【讨论】:

    猜你喜欢
    • 2013-12-25
    • 1970-01-01
    • 2016-05-01
    • 2016-04-03
    • 2018-04-06
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多