0

I am using CentOS6.9 and I am using python3.6 to load the c library from a .so file. However, I have encounter the following error:

OSError: /lib64/libc.so.6: version 'GLIBC_2.14' not found

I did some research and found out it is because centOS 6 is using version 2.12. I follow one of the post from here(https://stackoverflow.com/a/38317265/8406938) to install GLIBC_2.14 in centOS 6, and can now successfully run external applications if they're linked against this libc by first running:

export LD_LIBRARY_PATH=/opt/glibc-2.14

My question is after I install that, how do I use it in python such that I can load the library through ctypes, here is the code I load:

filepath = os.path.dirname(os.path.join(os.path.realpath(__file__)))
lib = CDLL(os.path.join(filepath, 'lib.so'))

I still get the error

OSError: /lib64/libc.so.6: version 'GLIBC_2.14' not found

after I install 2.14. Do I need to set something in python (like the path variable) in order to use it?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Allen W
  • 139
  • 10
  • Insofar as you're literally asking for the Python equivalent to `export LD_LIBRARY_PATH=...`, see the `os.environ` dictionary (which can be modified), and `os.putenv()`. – Charles Duffy Jan 09 '18 at 22:10
  • BTW, you might want to read `man dlopen` (the C library call used by `ctypes`) for platform- and version-specific details. For example, on (some versions of) Linux, only the value of `LD_LIBRARY_PATH` *at the time when the program was started* is honored. – Charles Duffy Jan 09 '18 at 22:15

1 Answers1

0

You can't. The library requires glibc 2.14 or later to be present in the process it's being loaded by, but the process has already loaded glibc 2.12 during startup. There is no way to load both versions of glibc at once.

Your options are:

  1. Rebuild the library against your system's libc.

  2. Upgrade your system to an OS release with a compatible version of glibc.

  3. Start Python with LD_LIBRARY_PATH=… to force it to use the newer version of glibc. (Avoid doing this unless there is no alternative; it may have unexpected repercussions.)