[英]How to pass a C string into a Zig function expecting a Zig string?
[英]How to include readline into a Zig project
我正在尝试在我的 Zig 项目中使用 readline。
我设法通过将其添加到构建文件中来使链接器找到它:
exe.linkLibC();
exe.addIncludeDir("/usr/local/opt/readline/include");
exe.addLibPath("/usr/local/opt/readline/lib");
即使它找到了 readline 定义,它似乎也没有“看到”C lib ...
错误:
▶ 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:
我怎样才能让它工作?
似乎问题不在构建文件中,而是在 cImport 中。
我正在这样做:
const readline = @cImport({
@cInclude("readline/readline.h");
});
由于错误消息抱怨来自 C 的 stdio.h 的内容,我也添加了以下内容:
const readline = @cImport({
@cInclude("stdio.h");
@cInclude("readline/readline.h");
});
现在 Zig 构建工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.