首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >libc crate在Windows上不提供sprintf

libc crate在Windows上不提供sprintf
EN

Stack Overflow用户
提问于 2019-08-21 21:02:04
回答 1查看 584关注 0票数 2

我用Rust编写了一个库,该库使用libc crate提供的sprintf函数进行C格式化。一切都可以在macOS和Linux上运行,但它不能在Windows上编译,因为sprintf函数不存在。

代码语言:javascript
复制
extern crate libc;
use libc::{c_char, c_double, sprintf};
代码语言:javascript
复制
let c_resfmt: CString =
    CString::new(c_resfmt).expect("Couldn't convert to c_resfmt to CString ");
let result_buffer: *mut c_char = CString::new("").expect("").into_raw();
unsafe {
    sprintf(result_buffer, c_resfmt.as_ptr(), scaled_result as c_double);
    let formatted_result = CString::from_raw(result_buffer).into_string().unwrap();
    ptr_result.with_result_value(formatted_result);
}
代码语言:javascript
复制
error[E0432]: unresolved import `libc::sprintf`
  --> src\stdf_helper\reader\mod.rs:12:13
   |
12 | use libc::{ sprintf, c_char, c_double };
   |             ^^^^^^^
   |             |
   |             no `sprintf` in the root
   |             help: a similar name exists in the module: `isprint`

有没有一个替代的或替代的名字?

EN

回答 1

Stack Overflow用户

发布于 2019-08-21 21:18:45

这可能是工具链的问题。

您可能正在macOS和Linux (*Nix)上使用GNU工具链

确保您安装并使用了最新和最好的MSVC工具链

有关更多信息,请阅读this article

如果您使用的是使用一个或另一个工具链构建的库,则需要将其与适当的

工具链进行匹配。如果您不确定,请使用MSVC;这是默认的,原因很充分。

在windows上使用MSVC。

票数 -3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57592290

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档