Title: How to link with a non-system libffi?
Type: Stage: patch review
Components: Build, ctypes Versions: Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Joshua Merchant, munocat, ned.deily, pda, pmpp, rnash, rosslagerwall,
Priority: normal Keywords: patch

Created on 2012-04-08 02:25 by pda, last changed 2020-09-14 17:11 by pmpp.

Pull Requests
URL Status Linked Edit
PR 20451 open rnash, 2020-05-27 14:41
Messages (10)
msg157776 - (view) Author: Paul A. (pda) Date: 2012-04-08 02:25
I trying to build python using an external libffi package I have installed -- is there some trick in directing --with-system-ffi to the path where it's located.  I don't see clues in config.log or anywhere to help.
msg157777 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2012-04-08 05:58
If it is in a non-standard location, try setting the environment variables:

LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir>
CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir>
msg157795 - (view) Author: Paul A. (pda) Date: 2012-04-08 16:17
On Sun, Apr 08, 2012 at 05:58:29AM +0000, Ross Lagerwall wrote:
> Ross Lagerwall <> added the comment:
> If it is in a non-standard location, try setting the environment variables:
> LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir>
> CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir>

I'm pretty sure I've already been doing that, but I'll verify again soon
when I get the chance.
msg157932 - (view) Author: Paul A. (pda) Date: 2012-04-10 02:52
Yes, I think my libffi setup is okay, but python apparently doesn't (according to the deeper-down log files I didn't initially know about).  The following is a suspicious-looking snippet from build/temp.hp-ux-B.11.31-ia64-2.7/libffi/config.log... I have to question the usefulness of that linker error message.  My immediate thought is that maybe conftstm.o is a 32-bit object file, but I don't see anything earlier in the log to indicate it was even created.

configure:6159: gcc463 -o conftest  -I. -IInclude -I./Include  -D_TERMIOS_INCLUDED  -I/usr/local/lp64/include -mlp64 -L/usr/local/src/Python-2.7.2 -L/usr/local/lp64/lib conftest.c conftstm.o >&5
ld: Mismatched Data ABI. Expected EF_IA_64_ABI64 but found None in file conftstm.o
Fatal error.
msg158004 - (view) Author: Paul A. (pda) Date: 2012-04-11 02:05
While this is no solution by any means, I think it'd be better for the scenario to be a fatal configure error.  After all, if I say --with-system-ffi, it means I really, really want want to use my own libffi.
msg368399 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-05-08 01:51
As of current Python 3 releases, like 3.8, the python build no longer vendors a copy of libffi for most Unix systems and for those systems the --with-system-ffi configure option is ignored, i.e. configure and will always try to find an external libffi.  On most systems, if you use are OK with using the system-supplied libffi, building and execution should usually "just work".  But if you want to use another version of libffi, for example, one that you build from source, it can be very non-intuitive of how to successfully do that *especially* if there is already a system libffi installed.  Depending on the system, you may need to set environment build variables like LDFLAGS, CFLAGS or PKG_CONFIG_PATH, and LD_LIBRARY_PATH for the Python build and/or you might need to override some of the libffi build variables to install in the proper locations for your system.  It seems like, as has been suggested in various places, should at least try to use pkg-config to find libffi library locations as it already does to find libffi include files. But that might not be enough to get a working setup, i.e. you still might need to set LD_LIBRARY_PATH or the equivalent to find libffi. At the very least, there should be some documentation on how to build with a non-system libffi.
msg368413 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-05-08 03:20
See also earlier discussions in Issue31710, Issue34823, Issue40488, and Issue40535, closed as duplicated of this issue.
msg370088 - (view) Author: Rupert Nash (rnash) * Date: 2020-05-27 14:43
I have just struggled with building CPython with the _ctypes module. Fundamentally, the problem appears to be that configure uses pkgconfig to find the libffi include directory, while's detect_ctypes only uses the global list of library directories.

I have made an attempt at fixing this by having configure produce the directory containing libffi (`LIBFFI_LIBDIR`) and use this. However I've hardly any experience with autotools, so I would be very happy to be corrected if this is no use at all.

The PR is
msg370580 - (view) Author: Warren Hardy (munocat) Date: 2020-06-01 21:04
I tried Rupert Nash’s changes to, configure, and 

I can confirm this changes worked for me. 

I had to edit the Makefile and enter the LIBFFI_INCLUDEDIR and LIBFFI_LIBDIR
this might be due to me being a newb about this stuff, and having some configuration setting wrong.
msg376885 - (view) Author: wang zhao ( Date: 2020-09-14 17:09
We managed to fixed on the server by following and got it sucuessfully compiled:
-./configure  --with-system-ffi  LDFLAGS="-L /home/XXX/installs/libffi-3.3/lib64/" CPPFLAGS="-I /home/XXX/installs/libffi-3.3/include/"
Date User Action Args
2020-09-14 17:11:35pmppsetnosy: + pmpp
2020-09-14 +

messages: + msg376885
versions: - Python 3.9
2020-08-14 16:02:50Joshua Merchantsetnosy: + Joshua Merchant
2020-06-01 21:04:44munocatsetnosy: + munocat
messages: + msg370580
2020-05-27 14:43:24rnashsetmessages: + msg370088
2020-05-27 14:41:28rnashsetkeywords: + patch
nosy: + rnash

pull_requests: + pull_request19705
stage: needs patch -> patch review
2020-05-08 03:27:34ned.deilylinkissue40488 superseder
2020-05-08 03:24:54ned.deilylinkissue40535 superseder
2020-05-08 03:22:08ned.deilylinkissue34823 superseder
2020-05-08 03:21:22ned.deilylinkissue31710 superseder
2020-05-08 03:20:02ned.deilysettype: enhancement ->
messages: + msg368413
stage: needs patch
2020-05-08 01:51:01ned.deilysettitle: How to link with an external libffi? -> How to link with a non-system libffi?
nosy: + ned.deily

messages: + msg368399

versions: + Python 3.8, Python 3.9, - Python 2.7
components: + Build
2012-04-11 02:05:29pdasetmessages: + msg158004
2012-04-10 02:52:32pdasetmessages: + msg157932
components: + ctypes
2012-04-08 16:17:32pdasetmessages: + msg157795
2012-04-08 05:58:29rosslagerwallsetnosy: + rosslagerwall
messages: + msg157777
2012-04-08 02:25:34pdacreate