我正在尝试编译我的 boringssl 库包装器。我已经编译了肯定包含符号 AES_set_encrypt_key
的 crypto.lib 文件,根据命令判断:
nm crypto.lib --demangle
然后我生成了一个声明该符号的 FFI 文件:
use std::os::raw::{c_char, c_int, c_uchar, c_uint, c_void};
#[repr(C)]
pub struct aes_key_st {
pub rd_key: [u32; 60usize],
pub rounds: c_uint,
}
pub type AES_KEY = aes_key_st;
extern "C" {
pub fn AES_set_encrypt_key(key: *const u8, bits: c_uint, aeskey: *mut AES_KEY) -> c_int;
pub fn foo() -> c_int;
}
这是原始的 C 声明:
struct aes_key_st {
uint32_t rd_key[4 * (AES_MAXNR + 1)];
unsigned rounds;
};
typedef struct aes_key_st AES_KEY;
OPENSSL_EXPORT int AES_set_encrypt_key(const uint8_t *key, unsigned bits, AES_KEY *aeskey);
build.rs:
fn main() {
let out_dir = "<path_to_lib>"
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=static=crypto");
}
编译此代码时出现LNK2019(未解析的外部符号)
错误。
为什么会这样?
最佳答案
我用 32 位版本的 MSVC 编译了我的库,但是 Rust 用 64 位版本编译了程序。这就是发生冲突的原因。
关于windows - 在 Windows 上将 Rust 代码链接到 boringssl 时未解析的外部符号 AES_set_encrypt_key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52541868/