File tree Expand file tree Collapse file tree 2 files changed +4
-33
lines changed Expand file tree Collapse file tree 2 files changed +4
-33
lines changed Original file line number Diff line number Diff line change @@ -19,40 +19,11 @@ libc = { version = "0.2.146", default-features = false }
19
19
20
20
我们可能需要编译器的 nightly 版本来生成 ` #![no_std] ` 可执行文件,因为在许多平台上,我们必须提供不稳定的 ` eh_personality ` [ lang item] 。
21
21
22
- 可以通过两种方式控制入口点: ` #[start] ` 属性,或者用您自己的函数覆盖 C 语言 ` main ` 函数的默认实现。此外,还需要定义一个 [ panic handler function ] ( panic-handler.html ) 。
22
+ 你需要为你的目标平台定义一个适合的入口点符号,例如 ` main ` 、 ` _start ` 、 ` WinMain ` 或任何与你的目标平台相关的入口点名称 。
23
23
24
- 标记为 ` #[start ] ` 的函数会以与 C 语言相同的格式传递命令行参数(除了使用的确切整数类型):
24
+ 此外,你需要使用 ` #![no_main ] ` 属性,以防止编译器尝试自动生成入口点。
25
25
26
- ``` rust
27
- #![feature(start, lang_items, core_intrinsics, rustc_private)]
28
- #![allow(internal_features)]
29
- #![no_std]
30
-
31
- // 在 cfg(unix) 平台上,对于 `panic = "unwind"` 构建来说是必要的。
32
- #![feature(panic_unwind)]
33
- extern crate unwind;
34
-
35
- // 导入 crt0.o 可能需要的系统 libc 库。
36
- #[cfg(not(windows))]
37
- extern crate libc;
38
-
39
- use core :: panic :: PanicInfo ;
40
-
41
- // 本程序的入口点。
42
- #[start]
43
- fn main (_argc : isize , _argv : * const * const u8 ) -> isize {
44
- 0
45
- }
46
-
47
- // 编译器使用这些函数,但对于像这样的空程序来说并不需要。
48
- // 它们通常由 `std` 提供。
49
- #[lang = " eh_personality" ]
50
- fn rust_eh_personality () {}
51
- #[panic_handler]
52
- fn panic_handler (_info : & PanicInfo ) -> ! { core :: intrinsics :: abort () }
53
- ```
54
-
55
- 要覆盖编译器插入的 ` main ` shim,我们必须使用 ` #![no_main] ` 禁用它,然后使用正确的 ABI 和正确的名称创建适当的符号,这需要覆盖编译器的名称改编:
26
+ 另外,还需要定义一个[ panic 处理函数] ( panic-handler.html ) 。
56
27
57
28
``` rust
58
29
#![feature(lang_items, core_intrinsics, rustc_private)]
Original file line number Diff line number Diff line change 15
15
>
16
16
> 如果大家对于翻译有更好的建议或者想法,欢迎直接 PR~
17
17
>
18
- > 目前翻译基于 commit:d2c1d5cf8a296a481284252ddbb74211cc5782db ,基于时间:2025/01/20
18
+ > 目前翻译基于 commit:bc2298865544695c63454fc1f9f98a3dc22e9948 ,基于时间:2025/01/24
19
19
>
20
20
> Q:为什么不基于之前已有的中文版进行改进?
21
21
>
You can’t perform that action at this time.
0 commit comments