在 Rust 中使用 .c 源文件 [英] Using .c source files with Rust

查看:48
本文介绍了在 Rust 中使用 .c 源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有包含 .c 源文件的标准方法?

Is there a standard way to include .c source files?

到目前为止,我一直在使用 extern "C" { ... } 来公开函数,将 .c 编译为目标文件,运行 rustc 直到 ld 因未定义的引用而窒息,以及使用 错误后显示的参数:与 'cc' 链接失败,代码为 1;注意:cc 参数:... 运行 cc myobjfile.o ...

So far I've been using extern "C" { ... } to expose the functions, compiling .c to an object file, running rustc until ld chokes with an undefined reference, and using the arguments shown after error: linking with 'cc' failed with code 1; note: cc arguments: ... to run cc myobjfile.o ...

推荐答案

编者注:此答案早于 Rust 1.0,不再适用.

Editor's note: This answer predates Rust 1.0 and is no longer applicable.

Luqman 在 IRC 上给出了提示;在 crate 文件中使用 extern "C" { ... }#[link_args="src/source.c"]; 对我有用.

Luqman gave a hint on IRC; using extern "C" { ... } with #[link_args="src/source.c"]; in the crate file works for me.

这篇关于在 Rust 中使用 .c 源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆