13

When I try to build my own version of Python using:

./configure --enable-shared --prefix=/app/vendor/python-dev && make && make install

I see some errors during installation:

/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/libpython2.7.a: could not read symbols: Bad value

The problem starts when the linker tries to use /usr/local/lib/libpython2.7.a and not the newly compiled library.

How can I prevent the linker (configure/make) from using the python libraries installed on the system?

Xyand
  • 4,470
  • 4
  • 36
  • 63
  • `./configure --enable-shared --prefix=/app/vendor/python-dev && make && make install` works for me (from the [Python-2.7.5 tarball](http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2) on Ubuntu 13.04). If the error occurs during the `make` part, you'll have to include the full output from `make`. – Aya Jun 07 '13 at 15:44
  • This is the only error. It simply repeats for other modules as well. I'm using 2.7.4 tarball. But I have 2.7.4 on my machine, compiled statically (I guess without -fPIC). – Xyand Jun 07 '13 at 15:47
  • Sure, but the reason for the error will have happened much earlier in the build, so it's impossible to diagnose without more info. Take a look at [this](http://mail.python.org/pipermail/python-list/2010-September/587427.html), and the followups. I'm not sure if it's the same issue, but there's not much more I can do without seeing the output from `make`. – Aya Jun 07 '13 at 16:11
  • Here is the log http://pastebin.com/ZBUp2cnd. And yes, the post mentions the same problem. But without a solution. – Xyand Jun 07 '13 at 17:34
  • Did my solution work or not? – Aya Jun 08 '13 at 08:06

3 Answers3

13

This looks to be a misfeature of the setup.py script always including /usr/local in the search path when make builds the target sharedmods.

You'll have to manually frob the setup.py, so do the...

./configure --enable-shared --prefix=/app/vendor/python-dev

...first, then edit setup.py, find lines 442, 443, and 444 which should look like this...

if not cross_compiling:
    add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
    add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')

...and comment them out so they look like this...

# if not cross_compiling
    # add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
    # add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')

...then the make should work.

interpolack
  • 876
  • 10
  • 26
Aya
  • 39,884
  • 6
  • 55
  • 55
  • 2
    The if statement need to be commented out as well. Otherwise parser would be expecting an indented block which is the two add_dir_to_list lines. Just for future reference. – Xephon Dec 19 '13 at 14:12
  • i just met this issue when i was trying to recompile and reinstall python to /usr/local/lib again. In this case you have to use --prefix=/usr/local/lib again, and editing setup.py, as this answer suggests won't help. To fix it, I had to delete existing /usr/local/lib/libpython2.7.a file and /usr/local/lib/python2.7/ directory (maybe latter is not needed) – user920391 Aug 03 '15 at 19:40
5

I solved with this script:

# Python 2.7.6: 
wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared       LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Igor Ferreira
  • 51
  • 1
  • 2
0

I just moved /usr/local/lib/libpython2.7.a to /tmp

Blaze
  • 1,530
  • 2
  • 15
  • 24