0

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.

olebole
  • 521
  • 4
  • 17
Evgenii
  • 36,389
  • 27
  • 134
  • 170
  • 2
    What is that IRAF library? The error message is quite clear, the library is not compiled with -fPIC, it is a static library. We should have duplicates around. This is not a Fortran or gfortran specific problem. – Vladimir F Героям слава Mar 02 '19 at 09:05
  • IRAF is an astronomical tool from http://iraf.noao.edu. The same Makefile works on a different PC with Ubuntu 16.04 gfortran 5.4.0, but breaks on Ubuntu 18.04 gfortran 7.3. In both cases the IRAF library files are the same. – Evgenii Mar 02 '19 at 09:12
  • 2
    Nevertheless, I feel it is natural to first try to follow the error message and only later try to compile different GCC instead. Especially considering it is a linker error so the difference may be in binutils, not in GCC. – Vladimir F Героям слава Mar 02 '19 at 09:15
  • Sorry, what do you mean? – Evgenii Mar 02 '19 at 10:13
  • 2
    The error is reported by `/usr/bin/ld`, not by gfortran. And in your other question you are trying to install different gfortran to get rid of this error. I do not think that is a good think to start with. First follow what the error message suggests. – Vladimir F Героям слава Mar 02 '19 at 10:20
  • Ok, that's good to know that it's not gfortran, thanks. "First follow what the error message suggests." sorry what does it suggest? – Evgenii Mar 02 '19 at 10:40
  • 2
    It suggests to recompile the IRAF library with `-fPIC`. Or use such a (dynamic) version, if it is already available. – Vladimir F Героям слава Mar 02 '19 at 10:53

1 Answers1

0

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
Evgenii
  • 36,389
  • 27
  • 134
  • 170