#Error Linking against C Linenoise: error: expected type '[*c]u8', found '*const [4:0]u8'

1 messages Ā· Page 1 of 1 (latest)

weak ice
#

I'm importing Linenoise (https://github.com/antirez/linenoise, located locally at deps/linenoise)
Here are the relevant portions of my code:

// build.zig
exe.addIncludePath(b.path("deps"));
// src/main.zig
const Linenoise = @cImport({
    @cInclude("linenoise/linenoise.c");
});

pub fn main() !void {
  _ = Linenoise.linenoise("prompt>");
}

When I execute zig build I get the following error:

$ zig build
/myprojectpathhere/.zig-cache/o/41e200993f7f9ddf9a76c95c36ecdb26/cimport.zig:1741:5: error: expected type '[*c]u8', found '*const [4:0]u8'
    "dumb",
    ^~~~~~

The relevant piece of code in the generated cimport.zig:

pub var unsupported_term: [4][*c]u8 = [4][*c]u8{
    "dumb",
    "cons25",
    "emacs",
    null,
};

What am I doing wrong, or is this a bug in Zig?

grizzled willow
#

If you think thats a mistake and the library author just forgot to mark it as const, you can just @constCast it

weak ice
#

But I shouldn't edit cimport.zig since it's generated, right?

grizzled willow
#

You can edit it and save it locally
Since youre vendoring it, it should be fine

#

You could also just edit the header files themselves since youre vendoring it

#

making it const is exclusively more permissive
So it shouldnt break any code

weak ice
#

Thanks! I've added const in linenoise.c (diff below) and compilation got past that error šŸ™Œ.

- static char *unsupported_term[] = {"dumb","cons25","emacs",NULL};
+ static const char *unsupported_term[] = {"dumb","cons25","emacs",NULL};

However, now I'm geting the below error:

install
└─ install myproject
   └─ zig build-exe pur Debug native 3 errors
error: ld.lld: undefined symbol: linenoiseEditMore
    note: referenced by cimport.zig:2379 (/myprojectpathhere/.zig-cache/o/6f2df6dd14cabaa92e3e85c240ac77d9/cimport.zig:2379)
    note:               /myprojectpathhere/.zig-cache/o/1a2ec50a8fe4fbffc0449a148326cc2c/myproject.o:(cimport.linenoiseBlockingEdit)
    note: referenced by cimport.zig:139 (/myprojectpathhere/.zig-cache/o/6f2df6dd14cabaa92e3e85c240ac77d9/cimport.zig:139)
    note:               /myprojectpathhere/.zig-cache/o/1a2ec50a8fe4fbffc0449a148326cc2c/myproject.o:(linenoiseEditFeed)
    note: referenced by cimport.zig:320 (/myprojectpathhere/.zig-cache/o/6f2df6dd14cabaa92e3e85c240ac77d9/cimport.zig:320)
    note:               /myprojectpathhere/.zig-cache/o/1a2ec50a8fe4fbffc0449a148326cc2c/myproject.o:(linenoiseEditFeed)
    note: referenced 1 more times
error: ld.lld: undefined symbol: enableRawMode
    note: referenced by cimport.zig:111 (/myprojectpathhere/.zig-cache/o/6f2df6dd14cabaa92e3e85c240ac77d9/cimport.zig:111)
    note:               /myprojectpathhere/.zig-cache/o/1a2ec50a8fe4fbffc0449a148326cc2c/myproject.o:(linenoiseEditStart)
    note: referenced by cimport.zig:587 (/myprojectpathhere/.zig-cache/o/6f2df6dd14cabaa92e3e85c240ac77d9/cimport.zig:587)
    note:               /myprojectpathhere/.zig-cache/o/1a2ec50a8fe4fbffc0449a148326cc2c/myproject.o:(linenoisePrintKeyCodes)
error: ld.lld: undefined symbol: getColumns
    note: referenced by cimport.zig:112 (/myprojectpathhere/.zig-cache/o/6f2df6dd14cabaa92e3e85c240ac77d9/cimport.zig:112)
    note:               /myprojectpathhere/.zig-cache/o/1a2ec50a8fe4fbffc0449a148326cc2c/myproject.o:(linenoiseEditStart)

Any ideas?

grizzled willow
#

Are you sure youre actually linking against the library

#

Not just cimporting the header