我正在学习DirectX和Rust,我想在我的项目中使用DX敏捷SDK. 为此,我需要在最终可执行文件中导出两个符号,以便DirectX可以加载系统中可用的最佳DLL,如this guide中所述.

这就是我try 过的:

#[used]
#[no_mangle]
#[export_name = "D3D12SDKVersion"]
pub static D3D12_SDK_VERSION: u32 = 711;    // SDK 1.711.3-preview

然后,我使用转储工具判断可执行文件是否包含导出的符号(它没有):

dumpbin .\test.exe /EXPORTS
Microsoft (R) COFF/PE Dumper Version 14.40.33521.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file .\test.exe

File Type: EXECUTABLE IMAGE

  Summary

        1000 .data
        4000 .pdata
       10000 .rdata
        1000 .reloc
       33000 .text

但我希望它输出如下内容:

dumpbin .\test.exe /EXPORTS
Microsoft (R) COFF/PE Dumper Version 14.40.33521.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file .\test.exe

File Type: EXECUTABLE IMAGE

Section contains the following exports for WinLauncher.exe

    00000000 characteristics
    FFFFFFFF time date stamp
        0.00 version
           1 ordinal base
           2 number of functions
           2 number of names

    ordinal hint RVA      name

          1    0 00030220 D3D12SDKVersion

  Summary

        1000 .data
        4000 .pdata
       10000 .rdata
        1000 .reloc
       33000 .text

我真的不知道如何设置编译器和构建脚本来导出这些代码.如有任何帮助,我们不胜感激!

推荐答案

默认情况下,Rust不会从可执行文件中导出内容.有-Z export-executable-symbols夜的旗帜可以传递给Rustc(例如cargo +nightly rustc -- -Zexport-executable-symbols)来输出它们,但在马厩我不相信这可以做到.

Rust相关问答推荐

空字符串转换为Box字符串时是否分配?<>

如何从polars DataFrame中获取一个列作为Option String?<>

使用Rust s serde_json对混合数据类型进行优化'

修改切片/引用数组

新创建的变量的绑定生存期

我可以在不收集或克隆的情况下,将一个带有Item=(key,val)的迭代器拆分成单独的key iter和val iter吗?

Rust中WPARAM和VIRTUAL_KEY的比较

不同类型泛型的映射

Tokio';s io::用Cursor拆分<;Vec<;u8>>;赢得';t get the full writted data

将特征与具有生命周期的关联类型一起使用时的生命周期方差问题

Rust 中的复合 `HashSet` 操作或如何在 Rust 中获得 `HashSet` 的显式差异/并集

详尽的匹配模式绑定

`UnsafeCell` 在没有锁定的情况下跨线程共享 - 这可能会导致 UB,对吗?

Rust 文件未编译到 dll 中

我可以禁用发布模式的开发依赖功能吗?

将多维数组转换为切片

`tokio::pin` 如何改变变量的类型?

有没有办法在 Rust 中对 BigInt 进行正确的位移?

返回 &str 但不是 String 时,borrow 时间比预期长

Rust:为什么在 struct 中borrow 引用会borrow 整个 struct?