24

I am trying to build Python 2.6 for QGIS on RHEL 5. During the making of QGIS I get the following error:

Linking CXX shared library libqgispython.so
/usr/bin/ld: /usr/local/lib/python2.6/config/libpython2.6.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/python2.6/config/libpython2.6.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [src/python/libqgispython.so.1.0] Error 1
make[1]: *** [src/python/CMakeFiles/qgispython.dir/all] Error 2
make: *** [all] Error 2

What I figure out from this error is that I need to build Python 2.6 with some flag, -fPIC. OK, so I found it in the configure.in file but it checks several conditions and on the basis of those conditions it assigns -fPIC to the CCSHARED flag.

What I did was that after all conditions were checked I added the following line to deliberately use CCSHARED as -fPIC.

CCSHARED="-fPIC";

But it did not work..

How to specify while configuring that I want to set CCSHARED as -fPIC?

0

9 Answers 9

24

Run configure with --enable-shared. Then -fPIC will be included as part of the shared flags.

5
  • 4
    Unfortunately, when I tried running ./configure --enable-shared, this caused many important Python built-in modules to fail to compile (I'm trying to compile Python 2.7.3 for a 64-bit Ubuntu 11.04 system). Instead of adding --enable-shared, I had to edit Makefile and add -fPIC after CC= as per ashishsony's answer below.
    – Jack Kelly
    Jul 10, 2012 at 10:49
  • 1
    My modules failed to build too, but that's because I had the bad libpython2.7a already installed into /usr/local/lib! Deleted that and reran make, and everything was happy.
    – Jay Levitt
    Aug 27, 2012 at 15:23
  • I was installing on scientific linux 6.4 using environment-modules. I had to delete previous installaiton Jun 25, 2013 at 6:51
  • 4
    for me running ./configure --enable-shared --with-pic worked
    – Tahtisilma
    Jul 23, 2015 at 8:32
  • You need to add CXXFLAGS and CFLAGS (as per @Crc's solution below). Otherwise, you get the same error about -fPIC (at least with Python 2.7.13). Also, --with-pic is not recognized. Here is what worked for me for Python 2.7.13: ./configure CFLAGS=-fPIC CXXFLAGS=-fPIC --enable-shared
    – Alex Quinn
    May 13, 2017 at 22:20
14

The following worked for me when I ran into this error:

make clean
./configure CFLAGS=-fPIC CXXFLAGS=-fPIC
0
6

I got it working by adding -fPIC after CC= gcc -pthread, i.e CC= gcc -pthread -fPIC in the Makefile.

1
  • On CentOS 6.5, compiling Python-2.7.5 with ./configure --enable-shared resulted in an error: '.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC. I had to edit the Makefile and add -fPIC to the variable as described. This fixed it but it bugs me that I had to do this, but compiling on other machines with Mac and Ubuntu never had this issue, I will investigate further if I have the time. Jan 7, 2014 at 18:34
3
  1. Run ./configure --help, possibly piping to grep PIC, to see if there's an option to enable this
  2. Try setting the environment variable before running configure, e.g. CCSHARED="-fPIC" ./configure (as a single command, assuming bash)

If neither of those work, you need to read the configure code and understand the conditions it tests for better.

2

As noted elsewhere, running configure with --enable-shared should cause -fPIC to be included in the compiler flags. However, you may still see the "could not read symbols" error if you attempt to do a parallel build using, e.g., 'make -j8'. I had this same error on RHEL 5.2 and it only went away when I removed the '-j8' from my make invocation...

2
  • Just seconding evadeflow's answer: should use --enable-shared, and if that's not enough, build using only one thread (no -j option). I found the 2nd part necessary on a Scientific Linux SLF release 5.7 computer when installing Python 2.7.2. May 5, 2012 at 17:11
  • I find that if you build python first without configuring for --enable-shared, attempting to do so subsequently will cause epic fail as the static lib will be in the path, but the makefile is clearly looking for something else
    – Steven Lu
    Jul 21, 2013 at 23:58
0

Isn't that CCFLAGS? (Haven't been that side of the world for a while.)

0

rebuilt the openssl with ./config --prefix=/software/bea/openssl/100c --openssldir=/software/bea/openssl/100c/ssl shared -fPIC

and then also it dint work. it gave /usr/bin/ld: links failed. The we modifed the linking part in make file previously it was gcc -Wall -shared -o pwutil.so asciihex.o base64.o bitutils.o dict.o gen_rand.o key_schedule.o md5c.o pdg2_ecb.o pwutils.o random_data.o hexutils.o des3crypt.o blowcrypt.o /software/bea/openssl/1.0.0c/lib/libcrypto.a

we changed libcrypto.a to libcrypto.so after rebuilding with shared option and - fPIC

gcc -Wall -shared -o pwutil.so asciihex.o base64.o bitutils.o dict.o gen_rand.o key_schedule.o md5c.o pdg2_ecb.o pwutils.o random_data.o hexutils.o des3crypt.o blowcrypt.o /software/bea/openssl/1.0.0c/lib/libcrypto.so

and it worked

0

The following has an example of passing fPIC to configure

0

I got it working with:

./configure --enable-shared --enable-pic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.