4

I am trying to compile libedit on linux using GCC 5.3 and am getting a cryptic error message.

/home/mybin/libgcc/x86_64-unknown-linux-gnu/5.3.0/../../../libcurses.a(lib_termcap.o): relocation R_X86_64_32 against `_nc_globals' can not be used when making a shared object; recompile with -fPIC
/home/mybin/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../libcurses.a: could not read symbols: Bad value

To what does the recompile with -fPIC refer, ncurses or libedit? and then how do I pass the -fPIC flag. I have tried adding CFLAGS=-fPIC to the configure of ncurses & libedit but still did not work.

I have found may posts on SO about what -fPIC is, but none on how to set the flag.

thanks Art

art vanderlay
  • 2,341
  • 4
  • 35
  • 64

3 Answers3

4

Perhaps you ran afoul of the changes outlined in Fedora's Changes/Harden All Packages which use a linker spec that only works if you have compiled using either -fPIC or -fPIE. The linker message is almost useless; only the part about -fPIC has any usefulness.

To address this problem, you can add/modify the compiler flags in several ways. One of the simplest is to set it in the CFLAGS environment variable, e.g.,

export CFLAGS='-O -fPIC'

If you happen to be building ncurses, this means that you would have to also be configuring to build only shared libraries, e.g.,

configure --with-shared --without-normal --without-debug

Of course that all works best if you do not have a previous set of makefiles, etc.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • 1
    OMG you have helped me sooo much, I was about to give up on the learning the whole GCC thing as I could not find the rhyme or reason to this problem. Could you please also look at http://stackoverflow.com/questions/36669538/passing-gcc-flag-std-c11-cxxflags-or-cxx-or-cflags as I am sure you may be able to tell me what basics I am missing there as well. Many many thanks Art – art vanderlay Apr 16 '16 at 21:15
2

You're looking at the wrong part of the error message. The "relocation R_X86_64_32" means that you're trying to build 32-bit code against a 64-bit library or vice versa. Make sure you have selected the same architecture for both.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • thanks for the pointer. I am compiling on a EC2 AWS AMI 64bit instance and have checked the configure --help, but can not find a reference to selecting a 64bit compile option. Is this a standard flag I need to set with GCC or is it usually program specific? Is there a way to confirm the ncurses is 64bit compiled? thanks Art – art vanderlay Apr 16 '16 at 17:34
  • Running `file` on the archive file should tell you want architecture it has been built for. – Ignacio Vazquez-Abrams Apr 16 '16 at 17:35
0

-fPIC is used to generate position independent code, it is used to create shared libraries. the make file has a problem, to fix it:
edit the Makefile, line 98 :

.c.o:
        ${CC} ${CFLAGS} -c $<

after CC add -fpic after CC like this :

.c.o:
        ${CC} -fpic ${CFLAGS} -c $<

also in line 103:

libedit.so: ${OOBJS}
        ${CC} --shared -o $@ ${OOBJS}

add -fpic after --shared:

libedit.so: ${OOBJS}
        ${CC} --shared -fpic -o $@ ${OOBJS}

if you are wondering what is the difference between -fPIC and -fpic note that they both do the same thing but -fpic is more efficient, check this for more informations What is the difference between `-fpic` and `-fPIC` gcc parameters?.

Community
  • 1
  • 1
Baroudi Safwen
  • 803
  • 6
  • 17
  • thank you for your input, but I could find no such reference to those lines in the Makefile for libedit. I am using version http://thrysoee.dk/editline/libedit-20150325-3.1.tar.gz. at line 98 I have `$(am__configure_deps) $(am__DIST_COMMON)` - thx Art – art vanderlay Apr 16 '16 at 18:01
  • i used this https://sourceforge.net/projects/libedit/, but your version worked just fine for me didn't even have to change anything just ./configure && make – Baroudi Safwen Apr 16 '16 at 18:42