Importing C header files ᴾᴴᴾ - chung-leong/zigar GitHub Wiki

JavaScript | PHP


To import functions from C, create a build.extra.h in the same directory as the Zig file. Add include statements in this file as you would in C. This file would be translated into Zig by the compiler's translate-c subsystem and become available under the module name "c".

#include <stdio.h>
const c = @import("c");

pub fn hello() void {
    c.puts("Hello world!\n");
}
<?php

$m = zigar_use(__DIR__ . '/c-example-1.zig');

$m->hello();
Hello world!

Use a build.extra.zig file to add include directories, libraries, and C source files that need to be compiled as C.


Customizing build

⚠️ **GitHub.com Fallback** ⚠️