1

我有带有 CentOS 6.4 的系统,它带有 GNU Fortran (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)。

我正在做四倍精度计算,为此我安装了 devtoolset-6 w/oa 问题。由于系统安装了默认的 gcc/gfortran,我清除了 shell

env -i bash

然后我设置了 devtoolset-6 环境

scl enable devtoolset-6 bash 

如果我检查已安装的 gcc 和 gfortran 版本,它们如下

gcc (GCC) 6.3.1 20170216 (Red Hat 6.3.1-3)
GNU Fortran (GCC) 6.3.1 20170216 (Red Hat 6.3.1-3)

到目前为止,一切都很好。我还有一个下面给出的测试示例

implicit double precision(a-h,o-z)
print * , ' i:'
read(5,*) i
if(i.le.0) stop
a=i
b=sqrt(a)
print * , b
c=b*b
print * , c
end

编译

gfortran -fdefault-real-8 -o test.exe test.F

当我尝试编译时,出现以下错误

(.text+0x20): 对main' /tmp/cc7n6vIv.o: In functionljacoeff_':test.F:(.text+0xf0) 的未定义引用: 对_gfortran_transfer_real128_write' test.F:(.text+0x16b): undefined reference to_gfortran_transfer_complex128_write' 的未定义引用 test.F:(.text+0x1ea): 对 `_gfortran_transfer_complex128_write' 的未定义引用 collect2: 错误: ld 返回 1 个退出状态

起初,我认为 _gfortran_transfer_real128_write 函数未定义,并使用默认的“nm”命令检查了 devtoolset-6 附带的库,并且确实该函数是在 libgfortran.a 中定义的。经过一些调试和更多调试后,我发现了“-v”选项并重新编译了代码,然后发现一些令人困惑的东西看起来像是 ld 检查系统旧库而不是 devtoolset-6 附带的库。LIBRARY_PATH 包括 /usr/lib/../lib64/ 文件夹,这会导致错误。无论如何,如果链接器找不到这些函数,它还应该检查 devtoolset-6 库。看起来这不会发生。我该如何解决这个链接错误?

驱动:gfortran -v -fdefault-real-8 -o test.exe test.F -l gfortran -lm -shared-libgcc 使用内置规范。COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/lto-wrapper 目标:x86_64-redhat-linux 配置:../configure - -enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-6/root/usr --mandir=/opt/rh/devtoolset-6/root/usr/分享/人 --infodir=/opt/rh/devtoolset-6/root/usr/share/info --with-bugurl= http://bugzilla.redhat.com/bugzilla--enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique -object --enable-linker-build-id --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --disable-libgcj --with-default-libstdcxx-abi=gcc4 -兼容 --with-isl=/builddir/build/BUILD/gcc-6.3.1-20170216/obj-x86_64-redhat-linux/isl-install --enable-libmpx --with-mpc=/builddir/build/ BUILD/gcc-6.3.1-20170216/obj-x86_64-redhat-linux/mpc-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux 线程模型:posix gcc 版本6.3.1 20170216 (Red Hat 6.3.1-3) (GCC) COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8' '-o' 'test.exe' '-shared-libgcc' '-mtune=generic ''-march=x86-64'/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/f951 test.F -fixed-form -cpp=/tmp/ccjQiTpi.f90 -quiet -v 测试。 F -quiet -dumpbase test.F -mtune=generic -march=x86-64 -auxbase test -version -fdefault-real-8 -fintrinsic-modules-path /opt/rh/devtoolset-6/root/usr/lib/ gcc/x86_64-redhat-linux/6.3.1/finclude -o /tmp/cceJeO1o.s GNU Fortran (GCC) 版本 6.3.1 20170216 (Red Hat 6.3.1-3) (x86_64-redhat-linux) 由 GNU 编译C 版本 6.3.1 20170216 (Red Hat 6.3.1-3)、GMP 版本 4.3.1、MPFR 版本 2.4.1、MPC 版本 0.8.1、isl 版本 0.14 或 0.13 GGC 启发式:--param ggc-min-expand =100 --param ggc-min-heapsize=131072 忽略不存在的目录 "/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include-fixed" 忽略不存在的目录"/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../x86_64-redhat-linux/include" #include " ...” 搜索从这里开始:#include <...> 搜索从这里开始:/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/finclude /opt/ rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include /usr/local/include /opt/rh/devtoolset-6/root/usr/include /usr/include 结束搜索列表. GNU Fortran2008 (GCC) version 6.3.1 20170216 (Red Hat 6.3.1-3) (x86_64-redhat-linux) 编译 GNU C version 6.3.1 20170216 (Red Hat 6.3.1-3), GMP版本 4.3.1、MPFR 版本 2.4.1、MPC 版本 0.8.1、isl 版本 0.14 或 0.13 GGC 启发式:--param ggc-min-expand=100 --param ggc-min-heapsize=131072 COLLECT_GCC_OPTIONS='-v ' '-fdefault-real-8' '-o' 'test.exe' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/as -v - -64 -o /tmp/cc7n6vIv.o /tmp/cceJeO1o.s 使用 BFD 版本 2.27-8.el6 的 GNU 汇编器版本 2.27 (x86_64-redhat-linux) 从 /opt/rh/devtoolset-6/root/ 读取规范usr/lib/gcc/x86_64-redhat-linux/6.3.1/libgfortran.spec 将规范库重命名为 liborig COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8' '-o' 'test.exe' '-shared -libgcc' '-mtune=generic' '-march=x86-64' COMPILER_PATH=/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/:/opt/ rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/:/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/:/ opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/:/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/LIBRARY_PATH=/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3。 1/:/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64/:/lib/.. /lib64/:/usr/lib/../lib64/:/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../.. /:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8' '-o' 'test.exe' '-shared-libgcc' '-mtune=generic' '-march= x86-64' /opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/collect2 -plugin /opt/rh/devtoolset-6/root/usr/libexec/gcc /x86_64-redhat-linux/6.3.1/liblto_plugin.so -plugin-opt=/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/lto-wrapper -插件选择=-fresolution=/tmp/ccQAAlqC。res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lquadmath -plugin-opt=-pass-through=-lm - plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin- opt=-pass-through=-lgcc --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86 -64.so.2 -o test.exe /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o /opt/rh/devtoolset-6/root/usr/ lib/gcc/x86_64-redhat-linux/6.3.1/crtbegin.o -L/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1 -L/opt/ rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64 -L/lib/../lib64 -L/usr /lib/../lib64 -L/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../.. /tmp/cc7n6vIv.o -lgfortran -lm -lgcc_s -lgcc -lquadmath -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/ crtend.o /usr/lib/../lib64/crtn.o /usr/lib/../lib64/crt1.o:在函数中 _start': (.text+0x20): undefined reference tomain'/tmp/cc7n6vIv.o:在函数ljacoeff_': test.F:(.text+0xf0): undefined reference to _gfortran_transfer_real128_write'test.F:(.text+0x16b):未定义引用_gfortran_transfer_complex128_write' test.F:(.text+0x1ea): undefined reference to _gfortran_transfer_complex128_write'collect2:错误:ld 返回 1 退出状态

4

0 回答 0