如何使cbindgen不包括stdlib.h?

huangapple go评论81阅读模式
英文:

How can I make cbindgen not include stdlib.h?

问题

我正在一个嵌入式项目中使用自定义的libc。我尝试将Rust集成到项目中,但不允许包含stdlib.h。我正在使用cbindgen生成Rust库的头文件,我想知道如何使其不包括libc?

英文:

I am working in an embedded project using a custom libc. I am trying to integrate Rust into the project and I am not allowed to include the stdlib.h, I am using cbindgen to generate the header file for the rust library and I would like to know how can I make it not include the libc?

答案1

得分: 2

创建一个cbindgen.toml文件,并在其中设置以下内容:

# 是否应禁止cbindgen的默认C/C++标准导入。这些导入通常包含在默认情况下,因为我们生成的头文件通常需要它们(例如uint32_t)。当前生成的导入包括:

# * 对于C: <stdarg.h>,<stdbool.h>,<stdint.h>,<stdlib.h>,<uchar.h>

# * 对于C++: <cstdarg>,<cstdint>,<cstdlib>,<new>,<cassert>(取决于配置)

# 默认值:false
no_includes = true

更多信息请查看:https://github.com/mozilla/cbindgen/blob/master/docs.md.

英文:

Create a cbindgen.toml file and set in it:

# Whether cbindgen&#39;s default C/C++ standard imports should be suppressed. These
# imports are included by default because our generated headers tend to require
# them (e.g. for uint32_t). Currently, the generated imports are:
#
# * for C: &lt;stdarg.h&gt;, &lt;stdbool.h&gt;, &lt;stdint.h&gt;, &lt;stdlib.h&gt;, &lt;uchar.h&gt;
#
# * for C++: &lt;cstdarg&gt;, &lt;cstdint&gt;, &lt;cstdlib&gt;, &lt;new&gt;, &lt;cassert&gt; (depending on config)
#
# default: false
no_includes = true

https://github.com/mozilla/cbindgen/blob/master/docs.md.

huangapple
  • 本文由 发表于 2023年7月10日 20:20:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76653685.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定