如何导出 Rust 二进制文件中的符号

问题描述 投票:0回答:1

我正在学习 DirectX 和 rust,我想在我的项目中使用 DX Agility SDK。 为此,我需要在最终可执行文件中导出两个符号,以便 DirectX 可以加载系统中可用的最佳 dll,如本指南中所述。

这是我尝试过的:

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

然后我使用 dumpbin 工具检查可执行文件是否包含导出的符号(没有):

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 directx rust-cargo directx-12 cargo
1个回答
0
投票

Rust 默认情况下不会从可执行文件中导出内容。存在

-Z export-executable-symbols
夜间标志,可以传递给 rustc(例如
cargo +nightly rustc -- -Zexport-executable-symbols
)来导出它们,但在稳定版上我不相信这是可以做到的。

© www.soinside.com 2019 - 2024. All rights reserved.