fortranlinker-errorsgfortraniraf

Error linking IRAF library relocation R_X86_64_32 against can not be used


I'm trying to compile a program called DAOSPEC written in Fortran. It gives me the following error (among similar others):

/usr/bin/ld: /home/osboxes/iraf/bin.linux64//libimfort.a(imakwc.o): relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIC

See the full log here.

How do I fix it?

My Makefile

FCOMP = gfortran
FFLAGS = -Wall -Wextra -fPIC -fmax-errors=1 -O3 -march=native -ffast-math -funroll-loops

.SUFFIXES: .o .f
.f.o:
    $(FCOMP) -c $(FFLAGS) $<

default : daospec

daospec: daospec.o lnxsubs.o iosubs.o mathsubs.o bothsubs.o
    $(FCOMP) -o daospec daospec.o lnxsubs.o iosubs.o mathsubs.o bothsubs.o -L/usr/local/lib/ -lcfitsio -lplotsub -ldevices -lutils -L/usr/lib/x86_64-linux-gnu/ -lX11 -L/home/YOUR_USERNAME/iraf/bin.linux64/ -limfort -lsys -lvops -L/home/YOUR_USERNAME/iraf/unix/bin.linux64/ -los -lf2c -lcurl 

clean:
    rm -rf daospec *.o

The same Makefile works on a different PC with Ubuntu 16.04 gfortran 5.4, but breaks on Ubuntu 18.04 gfortran 7.3. In both cases the IRAF library files are the same.


Solution

  • I have managed to solve the problem, with help from Vladimir F. Ubuntu 18.04 uses PIE, position independent executables (source), and thus it requires libraries to be built with -fPIC option. The libraries in the official IRAF distribution that I used were not build with -fPIC, and that's what caused my errors.

    Fortunately, one can now install IRAF libraries from the iraf-dev package on Ubuntu 18.04:

    sudo apt-get install iraf-dev
    

    Alternatively, one can compile IRAF from Github's iraf-community/iraf repository with -fPIC option.

    Lastly, I modified the Makefile to use the new locations of IRAF library files: /usr/lib/iraf/bin/ and /usr/lib/iraf/unix/bin/.

    FCOMP = gfortran
    FFLAGS = -Wall -Wextra -fPIC -fmax-errors=1 -O3 -march=native -ffast-math -funroll-loops
    
    .SUFFIXES: .o .f
    .f.o:
      $(FCOMP) -c $(FFLAGS) $<
    
    default : daospec
    
    daospec: daospec.o lnxsubs.o iosubs.o mathsubs.o bothsubs.o
      $(FCOMP) -o daospec daospec.o lnxsubs.o iosubs.o mathsubs.o bothsubs.o -L/usr/local/lib/ -lcfitsio -lplotsub -ldevices -lutils -L/usr/lib/x86_64-linux-gnu/ -lX11 -L/usr/lib/iraf/bin/ -limfort -lsys -lvops -L/usr/lib/iraf/unix/bin/ -los -lf2c -lcurl
    
    clean:
      rm -rf daospec *.o