我用Rust编写了一个库,该库使用libc crate提供的sprintf函数进行C格式化。一切都可以在macOS和Linux上运行,但它不能在Windows上编译,因为sprintf函数不存在。
extern crate libc;
use libc::{c_char, c_double, sprintf};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);
}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`有没有一个替代的或替代的名字?
发布于 2019-08-21 21:18:45
这可能是工具链的问题。
您可能正在macOS和Linux (*Nix)上使用GNU工具链
确保您安装并使用了最新和最好的MSVC工具链
有关更多信息,请阅读this article
如果您使用的是使用一个或另一个工具链构建的库,则需要将其与适当的
工具链进行匹配。如果您不确定,请使用MSVC;这是默认的,原因很充分。
在windows上使用MSVC。
https://stackoverflow.com/questions/57592290
复制相似问题