Search code examples
c++linkerqt5qmakelinker-flags

Linker complains about -fPIE yet unable to fix


I have a program which compiles and links fine on many different linux distros. Today I tried to build on Ubuntu 22 and got the error below on the linking step.

/usr/bin/ld: /commerciallibs/senselockAPI/Linux_X64/Ubuntu/libsenseEIV.a(s4wf.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:1005: autocommander] Error 1

I tried cleaning and recompiling with -fPIE flag, but the error remains. I am using C++17 and Qt5/QMake on Ubuntu 22 x86_64. The library file above (libsenseEIV.a) is a commercial library which is precompiled, so I cannot make any changes to it.

I am building an executable (not an SO). Can someone explain what is causing the error and how to fix it?


Solution

  • I had a problem with -fpie when trying to link in assembly code and I needed to use -fno-pie on the other stuff to get it to work.

    nasm -felf64 myproc.asm
    gcc -fno-pie myprog.c myproc.o -o myprog

    I still don't really know what the benefit of pie is in the first place.