首先确保您是passing the right linker-flavor。 rustc 可能错误地识别了您正在使用的链接器,并指定这可能会有所帮助。还要确保您使用正确的链接器。但是如果你真的想去掉那个论点,可以使用一些不稳定的特性。
没有删除单个链接器参数的通用方法。 eh_frame_header 目标属性指示链接器是否应插入 EH(异常处理)帧头。不稳定的 rustc 确实支持更改单个目标选项,但它有点复杂,并且在某些平台上只能处理 #![no_std] 二进制文件。您可能需要考虑手动调用链接器。
首先,将dump the JSON target metadata(使用夜间编译器)用于您正在编译的目标到,将[target] 替换为像thumbv7neon-unknown-linux-musleabihf 这样的目标三元组:
$ rustc -Z unstable-options --print target-spec-json --target [target] > target.json
target.json 现在具有特定于目标的编译信息。在某些目标(例如 WASM)上,默认情况下禁用 EH 帧头。如果您在 target.json 中看到这样的一行,那么您已经完成(并且不应该出现该错误):
"eh-frame-header": false,
如果您没有看到该行,则在打开大括号后将其添加到target.json,例如
{
"eh-frame-header": false,
...
您现在可以指定target.json 的路径,无论目标三元组通常在哪里。但是,您现在需要使用新的目标信息重新编译标准库(例如core 和std)。否则,编译器会告诉你the `target-17676080659170949227` target may not be installed。在不稳定的货物上,您可以使用-Z build-std
这样做:
$ cargo +nightly run -Z build-std=core --target target.json
这将比正常需要更长的时间,因为它需要重新编译core 标准库。并非所有平台都支持以这种方式编译更完整的 std 库,但如果您还想尝试构建整个 std 标准库,可以将 build-std=core 更改为仅 build-std。