SkillAgentSearch skills...

Libffi

A portable foreign-function interface library.

Install / Use

/learn @libffi/Libffi
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Status

libffi-3.5.2 was released on August 2, 2025.

What is libffi?

Compilers for high level languages generate code that follow certain conventions. These conventions are necessary, in part, for separate compilation to work. One such convention is the "calling convention". The "calling convention" is essentially a set of assumptions made by the compiler about where function arguments will be found on entry to a function. A "calling convention" also specifies where the return value for a function is found.

Some programs may not know at the time of compilation what arguments are to be passed to a function. For instance, an interpreter may be told at run-time about the number and types of arguments used to call a given function. Libffi can be used in such programs to provide a bridge from the interpreter program to compiled code.

The libffi library provides a portable, high level programming interface to various calling conventions. This allows a programmer to call any function specified by a call interface description at run time.

FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. The libffi library really only provides the lowest, machine dependent layer of a fully featured foreign function interface. A layer must exist above libffi that handles type conversions for values passed between the two languages.

Supported Platforms

Libffi has been ported to many different platforms.

At the time of release, the following basic configurations have been tested:

| Architecture | Operating System | Compiler | | --------------- | ---------------- | ----------------------- | | AArch64 (ARM64) | iOS | Clang | | AArch64 | Linux | GCC | | AArch64 | Windows | MSVC | | Alpha | Linux | GCC | | Alpha | Tru64 | GCC | | ARC | Linux | GCC | | ARC32 | Linux | GCC | | ARC64 | Linux | GCC | | ARM | Linux | GCC | | ARM | iOS | GCC | | ARM | Windows | MSVC | | AVR32 | Linux | GCC | | Blackfin | uClinux | GCC | | CSKY | Linux | GCC | | HPPA | HPUX | GCC | | HPPA64 | HPUX | GCC | | KVX | Linux | GCC | | IA-64 | Linux | GCC | | LoongArch64 | Linux | GCC | | M68K | FreeMiNT | GCC | | M68K | Linux | GCC | | M68K | RTEMS | GCC | | M88K | OpenBSD/mvme88k | GCC | | Meta | Linux | GCC | | MicroBlaze | Linux | GCC | | MIPS | IRIX | GCC | | MIPS | Linux | GCC | | MIPS | RTEMS | GCC | | MIPS64 | Linux | GCC | | Moxie | Bare metal | GCC | | OpenRISC | Linux | GCC | | PowerPC 32-bit | AIX | GCC | | PowerPC 32-bit | AIX | IBM XL C | | PowerPC 64-bit | AIX | IBM XL C | | PowerPC | AMIGA | GCC | | PowerPC | Linux | GCC | | PowerPC | Mac OSX | GCC | | PowerPC | FreeBSD | GCC | | PowerPC 64-bit | FreeBSD | GCC | | PowerPC 64-bit | Linux ELFv1 | GCC | | PowerPC 64-bit | Linux ELFv2 | GCC | | RISC-V 32-bit | Linux | GCC | | RISC-V 64-bit | Linux | GCC | | S390 | Linux | GCC | | S390X | Linux | GCC | | SH3 | Linux | GCC | | SH4 | Linux | GCC | | SH5/SH64 | Linux | GCC | | SPARC | Linux | GCC | | SPARC | Solaris | GCC | | SPARC | Solaris | Oracle Solaris Studio C | | SPARC64 | Linux | GCC | | SPARC64 | FreeBSD | GCC | | SPARC64 | Solaris | Oracle Solaris Studio C | | TILE-Gx/TILEPro | Linux | GCC | | VAX | OpenBSD/vax | GCC | | WASM32 | Emscripten | EMCC | | WASM64 | Emscripten | EMCC | | X86 | FreeBSD | GCC | | X86 | GNU HURD | GCC | | X86 | Interix | GCC | | X86 | kFreeBSD | GCC | | X86 | Linux | GCC | | X86 | OpenBSD | GCC | | X86 | OS/2 | GCC | | X86 | Solaris | GCC | | X86 | Solaris | Oracle Solaris Studio C | | X86 | Windows/Cygwin | GCC | | X86 | Windows/MinGW | GCC | | X86-64 | DragonFly BSD | GCC | | X86-64 | FreeBSD | GCC | | X86-64 | Linux | GCC | | X86-64 | Linux/x32 | GCC | | X86-64 | OpenBSD | GCC | | X86-64 | Solaris | Oracle Solaris Studio C | | X86-64 | Windows/Cygwin | GCC | | X86-64 | Windows/MinGW | GCC | | X86-64 | Mac OSX | GCC | | Xtensa | Linux | GCC |

Please send additional platform test results to libffi-discuss@sourceware.org.

Installing libffi

First you must configure the distribution for your particular system. Go to the directory you wish to build libffi in and run the "configure" program found in the root directory of the libffi source distribution. Note that building libffi requires a C99 compatible compiler. If you're building libffi directly from git hosted sources, configure won't exist yet; run ./autogen.sh first. This will require that you install autoconf, automake, libtool and texinfo.

You may want to tell configure where to install the libffi library and header files. To do that, use the --prefix configure switch. Libffi will install under /usr/local by default.

If you want to enable extra run-time debugging checks use the the --enable-debug configure switch. This is useful when your program dies mysteriously while using libffi.

Another useful configure switch is --enable-purify-safety. Using this will add some extra code which will suppress certain warnings when you are using Purify with libffi. Only use this switch when using Purify, as it will slow down the library.

If you don't want to build documentation, use the --disable-docs configure switch.

It's also possible to build libffi on Windows platforms with Microsoft's Visual C++ compiler. In this case, use the msvcc.sh wrapper script during configuration like so:

path/to/configure CC=path/to/msvcc.sh CXX=path/to/msvcc.sh LD=link CPP="cl -nologo -EP" CXXCPP="cl -nologo -EP" CPPFLAGS="-DFFI_BUILDING_DLL"

For 64-bit Windows builds, use CC="path/to/msvcc.sh -m64" and CXX="path/to/msvcc.sh -m64". You may also need to specify --build appropriately.

It is also possible to build libffi on Windows platforms with the LLVM project's clang-cl compiler, like below:

path/to/configure CC="path/to/msvcc.sh -clang-cl" CXX="path/to/msvcc.sh -clang-cl" LD=link CPP="clang-cl -EP"

When building with MSVC under a MingW environment, you may need to remove the line in configure that sets 'fix_srcfile_path' to a 'cygpath' command. ('cygpath' is not present in MingW, and is not required when using MingW-style paths.)

To build static library for ARM64 with MSVC using visual studio solution, msvc_build folder have aarch64/Ffi_staticLib.sln required header files in aarch64/aarch64_include/

SPARC Solaris builds require the use of the GNU assembler and linker. Point AS and LD environment variables at those tool prior to configuration.

For iOS builds, the libffi.xcodeproj Xcode project is available.

Configure has many other options. Use configure --help to see them all.

Once configure has finished, type "make". Note that you must be using GNU make. You can ftp GNU make from ftp.gnu.org:/pub/gnu/make .

To ensure that libffi is working as advertised, type "make check". This will require that you have DejaGNU installed.

To install the library and header files, type make install.

History

See the git l

View on GitHub
GitHub Stars4.2k
CategoryDevelopment
Updated2h ago
Forks804

Languages

C

Security Score

80/100

Audited on Mar 30, 2026

No findings