0

I am trying to use readline in my Zig project.

I managed to make the linker find it by adding this to the build file:

    exe.linkLibC();
    exe.addIncludeDir("/usr/local/opt/readline/include");
    exe.addLibPath("/usr/local/opt/readline/lib");

Even though it finds readline definitions it seems it doesn't "see" the C lib...

Error:

▶ zig build                         
./src/main.zig:1:18: error: C import failed
const readline = @cImport({
                 ^
/usr/local/opt/readline/include/readline/rltypedefs.h:71:36: note: unknown type name 'FILE'
typedef int rl_getc_func_t PARAMS((FILE *));
                                   ^
/usr/local/opt/readline/include/readline/readline.h:448:28: note: unknown type name 'FILE'
extern int rl_getc PARAMS((FILE *));
                           ^
/usr/local/opt/readline/include/readline/readline.h:578:8: note: unknown type name 'FILE'
extern FILE *rl_instream;
       ^
/usr/local/opt/readline/include/readline/readline.h:579:8: note: unknown type name 'FILE'
extern FILE *rl_outstream;
       ^
/usr/local/opt/readline/include/readline/readline.h:937:3: note: unknown type name 'FILE'
  FILE *inf;
  ^
/usr/local/opt/readline/include/readline/readline.h:938:3: note: unknown type name 'FILE'
  FILE *outf;
  ^
zig-lua...The following command exited with error code 1:

How can I make it work?

Renato
  • 12,940
  • 3
  • 54
  • 85

1 Answers1

0

It seems that the problem was not in the build file but in the cImport.

I was doing this:

const readline = @cImport({
    @cInclude("readline/readline.h");
});

As the error message was complaining about stuff from C's stdio.h, I added that too:

const readline = @cImport({
    @cInclude("stdio.h");
    @cInclude("readline/readline.h");
});

And now the Zig build works.

Renato
  • 12,940
  • 3
  • 54
  • 85