2

I have a project where I link to the BLAS library using the -lcblas flag. It used to compile fine, until after upgrading my system to Ubuntu 18.04 and GCC 7.3.0. Anyway, the compile command is

g++ -o @$ benchmark.o mine.o -lcblas

which yields the error

/usr/bin/x86_64-linux-gnu-ld: benchmark.o: relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output

This issue is possibly a duplicate, but I haven't been able to translate the solutions to other similar problems to my issue.

Adrian
  • 25
  • 1
  • 3
  • Hm, normally this would be a problem when building a shared library, but not when building a regular executable program. Are you sure you are not building an .so? – n. m. could be an AI May 07 '18 at 11:45
  • Ubuntu 18.04 : g++-5 (5.5), g++-6, g++-7 are all configured with PIE by default. Either use `g++ -no-pie -o ... ..` , or use g++-4.8 : `sudo apt install g++-4.8` . Ref. https://stackoverflow.com/questions/49101265/how-to-configure-gcc-to-use-no-pie-by-default – Knud Larsen May 07 '18 at 13:08
  • Please see https://superuser.com/questions/1320425/unable-to-compile-ffmpeg-and-libaom-from-source#comment1967576_1320425 ... about the "no PIE" `gcc54-c++_5.4.0-ubuntu16_amd64.deb` – Knud Larsen May 07 '18 at 18:56
  • @n.m. : I'm quite certain. That is, unless there are some things going on behind the scenes that I'm not aware of. I run the command exactly as written in my post, and I usually only see the *.o files, and no *.so files at all. – Adrian May 08 '18 at 11:21
  • @KnudLarsen Passing the -no-pie argument seems to do the trick. The build command ran with no errors. Will you post a response that I can accept? – Adrian May 08 '18 at 11:23

1 Answers1

2

can not be used when making a PIE object; recompile with -fPIC

Ubuntu 18.04 : g++-5 (5.5), g++-6, g++-7 are all configured with PIE by default.

Either use g++ -no-pie -o ... .. , or use g++-4.8 : sudo apt install g++-4.8 . Ref. How to configure gcc to use -no-pie by default?


Extra compiler for Ubuntu 16.04 and 18.04 → The "no PIE" g++54 : gcc54-c++_5.4.0-ubuntu16_amd64.deb → Provides /usr/bin/{gcc54, g++54, gfortran54}. Link : https://drive.google.com/file/d/1ptHLaZXImpeMzq4xuuGGn5VjrvxNSop3/view?usp=sharing

More gcc (no PIE) https://drive.google.com/drive/folders/1xVEATaYAwqvseBzYxKDzJoZ4-Hc_XOJm?usp=sharing

Knud Larsen
  • 5,753
  • 2
  • 14
  • 19