使用#![no_std]时的链接器错误与生锈错误
我有一个用Rust制作的小程序,它几乎什么也没做,但它不使用STD库。看起来像这样:
#![no_std]
#![no_main]
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}
我还必须将其添加到我的cargo.toml
中,否则它会抱怨eh_personality,不确定它是什么。
[package]
name = "hello-i686"
version = "0.1.0"
edition = "2021"
[dependencies]
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
但是,每当我尝试使用货物运行
进行编译时,我会得到错误:与CC链接到失败:退出状态:1
。
note: /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib/Scrt1.o: in function `_start':
/build/glibc/src/glibc/csu/../sysdeps/x86_64/start.S:103: undefined reference to `main'
/usr/bin/ld: /build/glibc/src/glibc/csu/../sysdeps/x86_64/start.S:115: undefined reference to `__libc_start_main'
collect2: error: ld returned 1 exit status
= help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
为了了解问题到底是什么,我试图使用C ++制作一个简单的Hello World程序,并自行链接它,当我不得不链接对象文件时,我意识到我从未触摸过C ++,我没有知道我在做什么。我发现crt0.o
在我的系统中找不到任何地方,我从来没有真正让我的C ++程序工作。我觉得问题是我的开发环境,但是我已经重新安装了大约3次基础,我不知道问题所在。我在Artix Linux上是否有帮助。当我使用性标准库时,一切都没有挂断。
I have a little program that I made with Rust, it does literally nothing, but it does not use the std library. It looks like this:
#![no_std]
#![no_main]
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}
I also had to add this to my cargo.toml
otherwise it complains about eh_personality, not sure what it is.
[package]
name = "hello-i686"
version = "0.1.0"
edition = "2021"
[dependencies]
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
But whenever I try to compile it with cargo run
, I get a error: linking with cc failed: exit status: 1
.
note: /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../lib/Scrt1.o: in function `_start':
/build/glibc/src/glibc/csu/../sysdeps/x86_64/start.S:103: undefined reference to `main'
/usr/bin/ld: /build/glibc/src/glibc/csu/../sysdeps/x86_64/start.S:115: undefined reference to `__libc_start_main'
collect2: error: ld returned 1 exit status
= help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
In pursuit to understand what exactly the problem is, I tried to make a simple hello world program with C++ and link it on my own, by the time I had to link my object files, I realized I have never touched C++ and I have no clue what I'm doing. I found out crt0.o
is nowhere to be found in my system, I never actually got my C++ program working. I feel like the problem is my development environment, but I've reinstalled base-devel about 3 times now, and I dont have a clue where the issue is. I'm on Artix Linux if that helps at all. When I do use the std library, everything goes off without a hitch.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要链接到
libc
以使其工作,因此请添加以下代码:这将解决有关丢失的
libc_start_main
的错误,但是您会收到有关错误的错误。缺少main
函数,您可以通过添加:You need to link to
libc
in order for this to work, so add the following code:This will fix the error about the missing
__libc_start_main
, but then you get an error about a missingmain
function which you can fix by adding: