119

After a succesful configure, make exits with snipped

gclosure.c:29:17: fatal error: ffi.h: No such file or directory
compilation terminated.

I have libffi installed, and locate ffi.h gives:

/home/luca/gcc4.6/gcc-4.6.0/libffi/include/ffi.h.in
/usr/include/x86_64-linux-gnu/ffi.h
/usr/share/doc/ghc-doc/html/users_guide/ffi.html
/usr/share/doc/libffi5/html/Using-libffi.html
deltaluca
  • 1,652
  • 2
  • 10
  • 9
  • 1
    You should check config.log to see what it says about ffi. Maybe it isn't finding it, but the script is buggy and doesn't exit with an error. Possibly it is confused by the new multilib include directory. Also check if the appropriate -I switch is passed to the compiler. – Jester Oct 19 '12 at 21:46

5 Answers5

271

If you have a Debian-based Linux OS with apt-get:

sudo apt-get install libffi-dev

With a Redhat-base OS:

yum install libffi-devel

With Alpine Linux:

apk add libffi-dev
Scott Skiles
  • 3,647
  • 6
  • 40
  • 64
Eric Milliot-Martinez
  • 4,076
  • 3
  • 23
  • 28
  • 6
    Alternatively, if you're using Redhat based OS, use yum install libffi-devel – Yonatan Jan 02 '14 at 13:34
  • 4
    Note that if you are cross-compiling glib on a 64bit system for 32bit then you need to install `libffi-dev:i386`. It wasn't obvious to me. :) – Björn Lindqvist May 29 '15 at 10:31
  • What if I don't have `sudo` permission? I have installed `libffi` in my home directory. – OliverShang Dec 01 '21 at 07:47
  • https://ubuntu.pkgs.org/18.04/ubuntu-main-amd64/libffi-dev_3.2.1-8_amd64.deb.html @OliverShang, you'll have to look up how to use the package after you've downloaded it. – Eric Milliot-Martinez Dec 03 '21 at 04:17
  • @EricMilliot-Martinez I mean I have compiled the package properly. Your link did not specify how to designate the path of libffi when compiling python. I can't copy it to `/usr/` since I don't have `sudo` permission. – OliverShang Dec 05 '21 at 08:02
  • @OliverShang, yes you mentioned you didn't have `sudo` permission and you're not able to ask an admin, hmm. Perhaps go into whichever python package is using libffi and edit the package itself in order to give it the new location you've put libffi in. The reason why is simple, it (libffi) is not in the default `/usr/` location it's normally in. How is the python package suppose to know that? You now need to edit and tell it the new location, you do that by going into the package and editing it. You have a unique problem that's likely gonna require a unique solution. – Eric Milliot-Martinez Dec 05 '21 at 17:35
  • 1
    @EricMilliot-Martinez Thanks, I think I should ask the admin to install this. – OliverShang Dec 07 '21 at 01:47
6

When compling libffi 3.0.9 from source code, the include/Makefile.in installs the includes in the ${PREFIX}/lib/libffi-3.0.9/include directory. I'm sure there's a WONDERFUL reason for that, but I'm annoyed by it.

This line fixes it, when compiling libffi:

/bin/perl -pe 's#^includesdir = .*#includesdir = \@includedir\@#' -i include/Makefile.in

The includes will now be installed in ${PREFIX}/include, which is /usr/local/include for me.

My full recipe is:

cd /var/tmp
rm -rf libffi-3.0.9
untgz /usr/local/src/utils/libffi-3.0.9.tar.gz
cd libffi-3.0.9
/bin/perl -pe 's#^AM_CFLAGS = .*#AM_CFLAGS = -g#' -i Makefile.in
/bin/perl -pe 's#^includesdir = .*#includesdir = \@includedir\@#' -i include/Makefile.in
./configure --prefix=/usr/local \
    --includedir=/usr/local/include
gmake
gmake install
Mark Solaris
  • 123
  • 1
  • 6
4

Resolved by manually setting LIBFFI_CFLAGS for location of ffi.h in configure

liberforce
  • 11,189
  • 37
  • 48
deltaluca
  • 1,652
  • 2
  • 10
  • 9
2

Check your GCC version and note this entry in the Debian Bug Archive: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=523869

It was the final solution to my particular issue (it looked exactly like what you report, but couldn't be solved with the solution above)... my problem had nothing to do with LIBFFI at all.

1

An old thread, but anyway...

After putting the required files in a location where they could be found, I got it working:

cp /usr/include/x86_64-linux-gnu/ffi* /usr/local/include/
cp /usr/lib/libffi.so /usr/local/lib/
Hammar
  • 21
  • 6