|
infix
A JIT-Powered FFI Library for C
|
This guide shows you how to build the infix library and add it to your C projects.
You will need a C17-compatible compiler:
For convenience, a build system is recommended:
The simplest way to use infix is to compile it directly into your project. This "unity build" approach requires no separate build steps and allows for better compiler optimizations.
src/ and include/ directories from the infix repository into your project (e.g., into a third_party/infix subdirectory).third_party/infix/src/infix.c to your list of source files to be compiled.include directory to your compiler's include search paths (e.g., -Ithird_party/infix/include).That's it. Your project will now build with the
infixlibrary compiled directly in.
If you prefer to build infix as a separate static library (.a or .lib) for system-wide installation or use with tools like pkg-config, follow the instructions for your preferred build system.
I personally use the perl based build script to develop, test, and fuzz infix. From the root of the infix project:
xmake provides an equally simple, cross-platform build experience. From the root of the infix project:
CMake can generate native build files for your environment (e.g., Makefiles, Visual Studio solutions).
To install to a custom location, use -DCMAKE_INSTALL_PREFIX=/path/to/install during the configure step.
GNU Make (Linux, macOS):
NMake (Windows with MSVC): Open a Developer Command Prompt and run:
When building infix as a shared library (DLL/.so), you must ensure that only the public API is exported.
Windows (DLL):
INFIX_BUILDING_DLL when compiling the library. This ensures that __declspec(dllexport) is applied only to public API functions, preventing internal symbols from polluting the DLL export table.INFIX_USING_DLL when compiling code that links against the infix DLL. This applies __declspec(dllimport) to the function declarations.Linux/macOS: All public functions are marked with INFIX_API (default visibility). Internal functions are marked with INFIX_INTERNAL (hidden visibility). The provided build scripts automatically set -fvisibility=hidden to ensure INFIX_INTERNAL works as intended.
Static Library: Do not define INFIX_BUILDING_DLL or INFIX_USING_DLL. This is the default.
The provided build scripts (perl, xmake, CMake, Makefiles) handle these definitions automatically when you select a shared library build.
For minimal environments or direct embedding, you can compile the library manually. The Perl-based builder is also available for advanced development tasks. For details, see the original INSTALL.md.
Once infix is built and installed, you can link it into your application.
If you installed infix to a standard or custom location, you can use find_package in your CMakeLists.txt:
A infix.pc file is generated for use with pkg-config, which is useful in Makefiles or autotools projects.
If you are using xmake for your project, you can add infix as a dependency in your xmake.lua.
If you've added the infix source to a subdirectory (e.g., libs/infix), you can configure VS Code's IntelliSense and build tasks.
**.vscode/c_cpp_properties.json** (for IntelliSense)
**.vscode/tasks.json** (for Building)