windows - 在 Windows 上将 Rust 代码链接到 boringssl 时未解析的外部符号 AES_set_encrypt_key

标签 windows visual-c++ rust

我正在尝试编译我的 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/

相关文章:

windows - 我可以从 Windows 中的用户模式程序读取 CPU 性能计数器吗?

c++ - 摆脱我的 Release 应用程序中的 msvcr120.dll/msvcp120.dll 依赖项 (VC++ 2013)

visual-c++ - 错误 : The Side-by-Side configuration information in "BLAH.EXE" contains errors

rust - 如何为库指定macOS部署目标?

generics - 算术运算的 Rust 泛型

rust - 如何借用对 Option<T> 中内容的引用?

c# - 在 .Net 下为低完整性进程添加写访问权限

windows - 如何创建名称大小写不同的目录? (区分大小写的 CreateDirectory 函数)

windows - 列出在任意PE(EXE)文件中链接的DLL的名称

visual-studio - DSOFramer 在另一个窗口中关闭 Excel 文档。如果文件中未保存数据,dsoframer 无法打开并显示 "Attempt to access invalid address"