6

I'm trying to compile mod_wsgi (version 3.3), Python 2.6, on a CentOS server - but under virtualenv, with no success. I'm getting the error:

/usr/bin/ld: /home/python26/lib/libpython2.6.a(node.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC

/home/python26/lib/libpython2.6.a: could not read symbols: Bad value

According to the mod_wsgi Installation Issues docs, it could be that the libpython2.6.a file:

  • isn't there
  • wasn't generated with shared
  • was generated for a 32-bit machine, not 64-bit.

Well, the file is in the right place, and readable. I tried to recompile Python 2.6 with the --enable-shared option, but the entire compilation blew up, with roughly every file giving the same error, that libpython2.6.a was hosed.

I don't know that Python was compiling for 64-bit, but when I ran it, and did:

import platform
print platform.platform()
>>>Linux-2.6.18-028stab070.4-x86_64-with-redhat-5.6-Final

Since Python thinks it's on a x86_64, I would hope that it compiled for 64-bit - if anyone has any way of confirming that, I'd appreciate it.

I tried configuring the mod_wsgi Makefile with both with and without --python=/home/[...]/python2.6, both ways blew up.

I also tried compiling mod_wsgi outside of virtualenv, using Python 2.4, and it worked fine. Unfortunately, that doesn't help me if I'm going to be using virtualenv :)

Anyone know how I can get mod_wsgi to compile under virtualenv?

John C
  • 6,285
  • 12
  • 45
  • 69
  • Note - I just tried compiling *not* under `virtualenv`, but still pointing --with-python to the latest version, as done in [this article about wsgi](http://toic.org/2011/03/27/wsgi-on-cpanel-improved/), but that also had no effect. – John C May 24 '11 at 21:47
  • Start with fresh Python source code tree and do again with --enable-shared option. You likely didn't clean the old source out properly when recompiling it with different options. – Graham Dumpleton May 24 '11 at 22:38
  • @Graham, thanks,actually, I just finished doing that - but one difference is that I put the --enable-shared option at the *end* of the command line, after the --with-python, and it worked. Also, when I compiled mod_wsgi, it got no errors - unfortunately, doing an *ldd* command on the mod_wsgi.so file gave me `libpython2.6.so.1.0 not found`. It *looks* like it's in all the right places, but I may start linking it to random locations just to see what happens. :) – John C May 24 '11 at 22:51
  • The --enable-shared flag is for configure for building Python not mod_WSGI. Search through the mod_WSGI site for mention of LD_RUN_PATH to solve the problem of mod_WSGI not find shared library at run time. – Graham Dumpleton May 24 '11 at 22:55
  • @Graham, sigh... I meant before --prefix when I was compiling Python. I suspect it needed the prefix first. Sorry, I've been staring at this screen all day, trying to get it working, and mis-typed. – John C May 24 '11 at 23:00
  • @Graham, on the bright side, LD_RUN_PATH actually seems to have worked - at least *ldd* is showing a link back to the .so file. Can you promote your comment to an Answer, please? Thanks. – John C May 24 '11 at 23:06

3 Answers3

8

Relevant parts of the documentation are:

http://modwsgi.readthedocs.io/en/develop/user-guides/installation-issues.html#mixing-32-bit-and-64-bit-packages

This mentions the -fPIC problem.

And:

http://modwsgi.readthedocs.io/en/develop/user-guides/installation-issues.html#unable-to-find-python-shared-library

This mentions need to use LD_RUN_PATH when shared library can't be found by mod_wsgi.

Additional information can be found about shared library issues as well as problems with mod_wsgi finding wrong Python installation at:

http://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#python-shared-library

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library was a great link for me. Thank you. Some of you who benefits from the links above may also need to take a closer look at the http://stackoverflow.com/questions/7880454/python-executable-not-finding-libpython-shared-library – Phyticist Dec 12 '16 at 18:51
3

If you have built Python from sources, add --enable-shared to configure. (It adds -fPIC)

olberg
  • 146
  • 3
1

You should recompile the libpython2.6.a with -fPIC to generate object.

For example:

gcc -fPIC -g -c -Wall xxx.c
Littm
  • 4,923
  • 4
  • 30
  • 38
zliu
  • 11
  • 1