1

I have system with CentOS 6.4 and it comes with GNU Fortran (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18).

I am doing quadrupule precision calculation and for that I installed devtoolset-6 w/o a problem. Since the system has a default gcc/gfortran installed, i cleared the shell with

env -i bash

and following that i set the devtoolset-6 environment

scl enable devtoolset-6 bash 

If i check the installed gcc and gfortran version, they are as following

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)

so far so good. I also have a testing example given below

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

compiled with

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

When i try to compile i am getting the following error

(.text+0x20): undefined reference to main' /tmp/cc7n6vIv.o: In functionljacoeff_':test.F:(.text+0xf0): undefined reference to _gfortran_transfer_real128_write' test.F:(.text+0x16b): undefined reference to_gfortran_transfer_complex128_write' test.F:(.text+0x1ea): undefined reference to `_gfortran_transfer_complex128_write' collect2: error: ld returned 1 exit status

At first, i thought the _gfortran_transfer_real128_write function is not defined and checked the library comes with devtoolset-6 using default "nm" command and indeed that function is defined in libgfortran.a. After some debugging and more debugging i discovered the "-v" option and recompiled the code, then noticed something confusing looks like ld checks the system old libraries instead of the one comes with devtoolset-6. The LIBRARY_PATH includes the /usr/lib/../lib64/ folder and that causes the error. In any case, If the linker couldn't find these function, it should also check the devtoolset-6 libraries. Looks like this doesn't happen. How could i resolve this linking error?

Driving: gfortran -v -fdefault-real-8 -o test.exe test.F -l gfortran -l m -shared-libgcc Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-6/root/usr --mandir=/opt/rh/devtoolset-6/root/usr/share/man --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-compatible --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 Thread model: posix gcc version 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 -ffixed-form -cpp=/tmp/ccjQiTpi.f90 -quiet -v test.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) version 6.3.1 20170216 (Red Hat 6.3.1-3) (x86_64-redhat-linux) compiled by GNU C version 6.3.1 20170216 (Red Hat 6.3.1-3), GMP version 4.3.1, MPFR version 2.4.1, MPC version 0.8.1, isl version 0.14 or 0.13 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include-fixed" ignoring nonexistent directory "/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /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 End of search list. GNU Fortran2008 (GCC) version 6.3.1 20170216 (Red Hat 6.3.1-3) (x86_64-redhat-linux) compiled by GNU C version 6.3.1 20170216 (Red Hat 6.3.1-3), GMP version 4.3.1, MPFR version 2.4.1, MPC version 0.8.1, isl version 0.14 or 0.13 GGC heuristics: --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 GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-8.el6 Reading specs from /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/libgfortran.spec rename spec lib to 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 -plugin-opt=-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: In function _start': (.text+0x20): undefined reference tomain' /tmp/cc7n6vIv.o: In function ljacoeff_': test.F:(.text+0xf0): undefined reference to _gfortran_transfer_real128_write' test.F:(.text+0x16b): undefined reference to _gfortran_transfer_complex128_write' test.F:(.text+0x1ea): undefined reference to _gfortran_transfer_complex128_write' collect2: error: ld returned 1 exit status

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

0 Answers0