Installation issue, linking Python with libffi to build ctypes module

Dear more experienced people,

I am trying to install Python on a Linux cluster, running RHEL7.
I need this to work two specific modules. One is Open3d, and the other is ctypes.
Open3d requires a Python version earlier than 3.8. Recommended is 3.7.7, so I am using that one.
I also really need the ctypes module for a specific user, so I need to link to libffi which contains ctypes.

I have compiled libffi-dev and get libraries and header files and everything.

When I try to compile Python, I use the following configure script to point to those libffi library and header files:

./configure \
--prefix=/trinity/opt/apps/software/python/open3D/Python-3.7.7/build \
--with-openssl=/trinity/opt/apps/software/openSSL/openssl-1.1.1u/build \
--with-libs=/trinity/opt/apps/software/libffi/libffi-3.4.2/build/lib64/libffi.a \
--without-system-ffi \
CFLAGS="-I/trinity/opt/apps/software/openSSL/openssl-1.1.1u/build/include \
        -I/trinity/opt/apps/software/libffi/libffi-3.4.2/build/include" \
LDFLAGS="-L/trinity/opt/apps/software/openSSL/openssl-1.1.1u/build/lib \
         -L/trinity/opt/apps/software/libffi/libffi-3.4.2/build/lib64" 

(it also needs openSSL for pip to work, hence those extra paths). make gives among much else:

INFO: Could not locate ffi libs and/or headers

Failed to build these modules:
_ctypes  

If I look in setup.py to see where this message comes from, I see:

    def configure_ctypes(self, ext):
        if not self.use_system_libffi:
            if host_platform == 'darwin':
                return self.configure_ctypes_darwin(ext)
            print('INFO: Could not locate ffi libs and/or headers')
            return False
        return True

Which appears to hint that Python requires to have use_system_libffi on, and even though I do not have it explicitly enabled in my configure script, config.log says it is turned on:

configure:10351: checking for --with-system-ffi
configure:10375: result: yes

I am at a loss as to what else I can do to have Python locate the libffi stuff.

What is the standard way to do this? What am I doing wrong?

Thank you very much for your time and expertise.

--with[out]-system-ffi just refers to whether or not the copy of libffi bundled with the Python sources will be used. You don’t need to specify it on Linux, as the bundled copy used on Linux was removed somewhere around Python 3.6, and so --with-system-ffi is forced to ‘yes’ (and you should have gotten a warning to that effect). I would definitely leave that argument out when you try again.

You could also try setting LIBFFI_INCLUDEDIR either at ./configure or make time (not sure which one might work :slight_smile: ). AFAICT, this is what setup.py looks at to try to find the “system” libffi.

I think it should be unnecessary to set --with-libs as you did.

All together, here’s my best suggestion:

./configure \
--prefix=/trinity/opt/apps/software/python/open3D/Python-3.7.7/build \
--with-openssl=/trinity/opt/apps/software/openSSL/openssl-1.1.1u/build \
LIBFFI_INCLUDEDIR=/trinity/opt/apps/software/libffi/libffi-3.4.2/build/include \
CFLAGS="-I/trinity/opt/apps/software/openSSL/openssl-1.1.1u/build/include \
        -I/trinity/opt/apps/software/libffi/libffi-3.4.2/build/include" \
LDFLAGS="-L/trinity/opt/apps/software/openSSL/openssl-1.1.1u/build/lib \
         -L/trinity/opt/apps/software/libffi/libffi-3.4.2/build/lib64" \
&& make LIBFFI_INCLUDEDIR=/trinity/opt/apps/software/libffi/libffi-3.4.2/build/include

Good luck! :slight_smile:

RHEL 7 + EPEL 7 has builds of python 3 are none of them usable?
Yes I know they are old versions, but RHEL 7 is very old…

Hi Zachary,

thank you for taking the time to help me out!

It almost worked. The configure stage passed succesfully, but the variable LIBFFI_INCLUDEDIR in the Makefile is left blank:

##########################################################################

LIBFFI_INCLUDEDIR=

##########################################################################

and specificying it as argument to make somehow did not catch, but after I explicitly set it to the proper path:

##########################################################################

LIBFFI_INCLUDEDIR=/trinity/opt/apps/software/libffi/libffi-3.4.2/build/include

##########################################################################

as in your example, I could create a proper binary that has open3D, Ctytpes, and OpenSSL all in it! :smile: Redid it with --enable-optimizations and I have a very happy user!

Thanks again!

1 Like