#How to import local C header files?

1 messages · Page 1 of 1 (latest)

covert arch
#

Hi. I want to import a local C header file through @cImport, but I can't figure out how to do so.

I've included the file in build.zig and the header file in on the same directory where build.zig lives.

Error log:

src/main.zig:2:11: error: C import failed
const c = @cImport(@cInclude("ee.h"));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.zig:2:11: note: libc headers not available; compilation does not link against libc

Here's what I've tried

const std = @import("std");
const c = @cImport(@cInclude("ee.h"));

pub fn main() !void {
    c.hi();
}

Header (ee.h)

#include <stdio.h>

void hi()
{
    printf("test");
}

...and build.zig
(too large, so posted here https://srcb.in/ozEtQSu5mE)

I've also tried to locate the header file in @cImport but nothing seems to work for me. Anyone knows what and where I'm missing something?

Thank you.

hallow valley
#

the argument to addIncludePath is the folder where the headers are

#

sooo "." i imagine

covert arch
#

Hmm good catch, but still...failed with same error

hallow valley
#

which error

#

i think you might need exe.linkLibC(); too

covert arch
#
const c = @cImport(@cInclude("ee.h"));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.zig:2:11: note: libc headers not available; compilation does not link against libc
elfin egret
#

because not always is needed C for the interaction

covert arch