-
Notifications
You must be signed in to change notification settings - Fork 6
Importing C header files
Chung Leong edited this page Jul 28, 2026
·
3 revisions
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");
}import { hello } from './c-example-1.zig';
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.