gcc compile error: /usr/bin/ld: gfx.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE

462 views Asked by At

Error is as follows:

/usr/bin/ld: gfx.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
make: *** [Makefile:4: project] Error 1

and when I add -fPIC or -fPIE, nothing changes. I know that the gfx.o library works, since it was working previously and still works when I ssh on my server.

Make file is as follows:

project: project.c
  gcc project.c gfx.o -lx11 -lm -fPIE -o -project
clean:
  rm project

I tried to use -fPIE and -fPIC in the makefile. I also treid uninstalling and reinstalling gcc and binutills, but nothing worked.

1

There are 1 answers

0
Tom O'Connor On

I figured out that putting -no-pie in the Makefile solves the issue. I don't know if there is a more permanent and widespread fix, but it works.