gpt4 book ai didi

macros - 包含的源看不到随使用导入的类型

转载 作者:行者123 更新时间:2023-11-29 08:25:42 24 4
gpt4 key购买 nike

我正在努力包括在内!一些自动生成的代码到一个模块中。我的模块看起来像...

use libc::c_int;

mod nif_versions {
include!(concat!(env!("OUT_DIR"), "/nif_versions.snippet"));
}

... nif_versions.snippet 看起来像 ...

const NIF_MAJOR_VERSION: c_int = 2;
const NIF_MINOR_VERSION: c_int = 7;

但这给了我以下错误:

/home/goertzen/ruster/target/build/ruster-7f1b6b5473eea720/out/nif_versions.snippet:1:26: 1:31 error: use of undeclared type name `c_int`
/home/goertzen/ruster/target/build/ruster-7f1b6b5473eea720/out/nif_versions.snippet:1 const NIF_MAJOR_VERSION: c_int = 2;
^~~~~
note: in expansion of include!

如果我跳过包含!并手动粘贴这两行,一切正常。此外,我必须将 include 包装在一个模块中才能使其正常工作。如果可能的话,我想摆脱它。

最佳答案

您只需将 use libc::c_int 移动到内部 mod 声明,因为 use 仅在它们所在的模块内有效使用:

mod nif_versions {
use libc::c_int;
include!(concat!(env!("OUT_DIR"), "/nif_versions.snippet"));
}

关于macros - 包含的源看不到随使用导入的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28097572/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com