我正在尝试通过rust-bindgen绑定tbs.h (基于TPM的服务)。
我有以下标题:
#ifndef TPM_WRAPPER_H
#define TPM_WRAPPER_H
#include <tbs.h>
#endifbuild.rs文件包含Windows SDK的include目录的路径:
use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rustc-link-lib=tbs");
println!("cargo:rerun-if-changed=include/tpm_wrapper.h");
let bindings = bindgen::Builder::default()
.header("include/tpm_wrapper.h")
.clang_arg("-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared")
.clang_arg("-v")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("tpm_bindings.rs"))
.expect("Couldn't write bindings!");
}当我尝试通过cargo build创建绑定并运行构建脚本时,我得到以下错误:
C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared\tbs.h:50:9: error: unknown type name 'UINT8'
C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared\tbs.h:99:5: error: unknown type name '_In_'
C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared\tbs.h:99:31: error: expected ')'
C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared\tbs.h:98:20: note: to match this '('是否缺少某些clang配置?
发布于 2020-07-29 00:59:07
产生的错误是windows-gnu toolchain的一部分。切换到stable-x86_64-pc-windows-msvc解决了这个问题。
rustup toolchain add stable-x86_64-pc-windows-msvc
rustup default stable-x86_64-pc-windows-msvcstable-x86_64-pc-windows-msvc需要windows生成工具,这些工具可以从visual studio安装程序获得,甚至可以作为独立工具。
更新
显然,对于所有窗口定义的类型,tbs.h都需要windows.h。由于bindgen中存在bug,因此存在将某些functions列入黑名单的解决方法
https://stackoverflow.com/questions/63131336
复制相似问题