infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
Building and Integrating <tt>infix</tt>

This guide shows you how to build the infix library and add it to your C projects.

Prerequisites

You will need a C17-compatible compiler:

  • GCC 8+
  • Clang 7+
  • Visual Studio 2019+

For convenience, a build system is recommended:


1. The Easiest Way: Add <tt>infix</tt> Directly to Your Project

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.

  1. Copy the src/ and include/ directories from the infix repository into your project (e.g., into a third_party/infix subdirectory).
  2. Add third_party/infix/src/infix.c to your list of source files to be compiled.
  3. Add the path to the 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 infix library compiled directly in.

</blockquote>

2. Building <tt>infix</tt> as a Standalone Library (Optional)

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.

Using perl (Recommended)

I personally use the perl based build script to develop, test, and fuzz infix. From the root of the infix project:

# Build the library
perl build.pl
# Run tests
perl build.pl test

Using xmake

xmake provides an equally simple, cross-platform build experience. From the root of the infix project:

# Build the library
xmake
# Run tests
xmake test

Using CMake

CMake can generate native build files for your environment (e.g., Makefiles, Visual Studio solutions).

# Configure the project in a 'build' directory
cmake -B build
# Compile the library
cmake --build build
# Run tests
ctest --test-dir build
# Install the library and headers (may require sudo)
cmake --install build

To install to a custom location, use -DCMAKE_INSTALL_PREFIX=/path/to/install during the configure step.

Using Makefiles

GNU Make (Linux, macOS):

make
make test
sudo make install

NMake (Windows with MSVC): Open a Developer Command Prompt and run:

nmake /f Makefile.win

Advanced Methods

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.


3. Linking Against a Pre-Built Library

Once infix is built and installed, you can link it into your application.

Using CMake with <tt>find_package</tt>

If you installed infix to a standard or custom location, you can use find_package in your CMakeLists.txt:

# Find the installed infix library.
# If installed to a custom path, run cmake with:
# cmake -DCMAKE_PREFIX_PATH=/path/to/your/install ..
find_package(infix REQUIRED)
# Link your application against the imported target.
target_link_libraries(my_app PRIVATE infix::infix)

Using pkg-config

A infix.pc file is generated for use with pkg-config, which is useful in Makefiles or autotools projects.

CFLAGS = `pkg-config --cflags infix`
LIBS = `pkg-config --libs infix`
my_app: main.c
$(CC) -o my_app main.c $(CFLAGS) $(LIBS)

Using xmake

If you are using xmake for your project, you can add infix as a dependency in your xmake.lua.

-- Tell xmake where to find the infix project
add_requires("infix", {git = "https://github.com/sanko/infix.git"})
-- Link your application against the "infix" library
target("my_app")
set_kind("binary")
add_files("src/*.c")
add_deps("infix")

Example: Visual Studio Code Configuration

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)

{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/libs/infix/include" // <-- Path to infix headers
],
"cStandard": "c17"
}
]
}

**.vscode/tasks.json** (for Building)

{
"version": "2.0.0",
"tasks": [
{
"label": "build with infix",
"type": "shell",
"command": "gcc",
"args": [
"-std=c17", "-g", "${file}",
"-I${workspaceFolder}/libs/infix/include", // Find infix headers
"-L${workspaceFolder}/libs/infix/build", // Find libinfix.a
"-linfix", // Link the library
"-o", "${fileDirname}/${fileBasenameNoExtension}"
]
}
]
}