[Seek Help] 【救救孩子!】Rust的Cargo 提示段错误,不知道错在哪里 Resolved
Tofloor
poster avatar
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-02-23 05:16
Author

【救救孩子!】Rust的Cargo 提示段错误,不知道错在哪里

只是一个很简单的hello world ,用rustc直接可以出,但是用cargo构建就出问题了

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/hello`
段错误

好烦,都搞好长时间了,连个hello world构建都出不来

sad 还想在deepin上做Rust开发的

===============================================

Rust版本:rustc 1.67.1 (d5a82bbd2 2023-02-07)

Cargo版本:cargo 1.67.1 (8ecd4f20a 2023-01-10)

deepin 社区版20.8

内核版本 5.15.77-amd64-desktop

编译器等相关版本:gcc (Uos 8.3.0.6-1+dde) 8.3.0, GNU ld (GNU Binutils for Uos) 2.31.1)

git version 2.20.1

cmake version 3.22.1

cc (Uos 8.3.0.3-3+rebuild) 8.3.0

ldd (Debian GLIBC 2.28.21-1+deepin-1) 2.28

===============================================================================

2022.02.22

终于找到问题了

在大佬的帮助下成功发现了原来罪魁祸首是这几行代码

/.cargo下的

config.toml 文件

# in .cargo/config
 
[target.'cfg(target_os = "linux")']
rustflags = ["-C", "link-arg=-nostartfiles"]
 
[target.'cfg(target_os = "windows")']
rustflags = ["-C", "link-args=/ENTRY:_start /SUBSYSTEM:console"]
 
[target.'cfg(target_os = "macos")']
rustflags = ["-C", "link-args=-e __start -static -nostartfiles"]

删掉就OK了sob 心酸,找了这么久原来一切都是 "link-arg=-nostartfiles"]

还以为是glibc,cmake,gcc,g++的版本太低的问题,搞到我还去学docker了,甚至想升级g++版本😂


千万千万不要在NTFS分区的源码里编译

Reply Favorite View the author
All Replies
2 / 2
To page
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-02-23 06:09
#21
sudo_free

好吧,竟然是改了编译参数……

这段编译参数是什么意思?

Reply View the author
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-02-23 06:10
#22
158******08

[target.'cfg(target_os = "linux")']
rustflags = ["-C", "link-arg=-nostartfiles"]

这行的问题,没链接startfiles,你是照着哪个大聪明复制的这个配置。。。

你把这行删了cargo clean一下在build就好了,你的上个帖子也是这个问题。。。

好像当时为了交叉编译塞进去的?这个设置不对吗。。。

Reply View the author
158******08
deepin
2023-02-23 06:15
#23
Claw龙虾bot

这段是什么意思? 当时好像网上找的复制下来的

不链接启动文件,反正只要用这个参数再用main当entry就肯定segfault

Reply View the author
sudo_free
deepin
2023-02-23 06:17
#24
Claw龙虾bot

好像当时为了交叉编译塞进去的?这个设置不对吗。。。

我觉得一般没人会手写这个config file。我在网上搜到出现这个参数的文章:“用rust编写操作系统”。

如果你是交叉编译到其它架构、操作系统,应该是 rustup target add ,然后安装系统依赖什么的

比如交叉编译到树莓派,可以参考下我之前抄的流程:

https://github.com/lasso-sustech/gps-analyzer/tree/master/sync_read

Reply View the author
158******08
deepin
2023-02-23 06:20
#25
Claw龙虾bot

好像当时为了交叉编译塞进去的?这个设置不对吗。。。

这个只有又特殊需求才会加这个参数,比如要运行在裸金属上,或者要完全不用libc什么的。

你根本不明白这段配置的意思就加上去才导致你折腾了这么长时间,要不是你无意中把这个贴出来你估计就要重装系统了

Reply View the author
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-02-23 06:22
#26
158******08

不链接启动文件,反正只要用这个参数再用main当entry就肯定segfault

所以这三个都要删掉对吧?还是只删除一个就OK了?

Reply View the author
158******08
deepin
2023-02-23 06:24
#27
Claw龙虾bot

所以这三个都要删掉对吧?还是只删除一个就OK了?

剩下两个只对另外两个系统生效

Reply View the author
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-02-23 06:42
#28
sudo_free

我觉得一般没人会手写这个config file。我在网上搜到出现这个参数的文章:“用rust编写操作系统”。

如果你是交叉编译到其它架构、操作系统,应该是 rustup target add ,然后安装系统依赖什么的

比如交叉编译到树莓派,可以参考下我之前抄的流程:

https://github.com/lasso-sustech/gps-analyzer/tree/master/sync_read

谢谢前辈,麻烦你们了

Reply View the author
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-02-23 06:42
#29
158******08

剩下两个只对另外两个系统生效

的确是这个问题,前面的问题也解决了,谢谢前辈,麻烦你们了

Reply View the author
158******08
deepin
2023-02-23 06:50
#30
Claw龙虾bot

的确是这个问题,前面的问题也解决了,谢谢前辈,麻烦你们了

加油把,初学rust的朋友,这个语言的争议非常多,无脑吹很多,无脑喷也很多,希望你能静下心学完。

初学的话我推荐Programming Rust的第二版看,https://cheats.rs 也是很好的助手,一般国内提问都去https://rustcc.cn 这个网站

Reply View the author
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-02-23 06:54
#31
158******08

加油把,初学rust的朋友,这个语言的争议非常多,无脑吹很多,无脑喷也很多,希望你能静下心学完。

初学的话我推荐Programming Rust的第二版看,https://cheats.rs 也是很好的助手,一般国内提问都去https://rustcc.cn 这个网站

https://cheats.rs 这个是怎么用的

初接触不太清楚😂

Reply View the author
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-02-23 06:55
#32
wlly-lzh
$ ls
Cargo.lock  Cargo.toml  src  target
$ cat src/main.rs 
fn main() {
    println!("Hello, world!");
}
$ tree
.
├── Cargo.lock
├── Cargo.toml
├── src
│   └── main.rs
└── target
    ├── CACHEDIR.TAG
    └── debug
        ├── a
        ├── a.d
        ├── build
        ├── deps
        │   ├── a-5db37415f70d84cf
        │   └── a-5db37415f70d84cf.d
        ├── examples
        └── incremental
            └── a-30mw4e3or7bor
                ├── s-gih0afe7ry-20lmu-kt7smmnlp3x6
                │   ├── 2jee1n4ukur4ok5i.o
                │   ├── 2jysz0emq293xez2.o
                │   ├── 30gmizbdmcotdhvo.o
                │   ├── 34t40cpjmmrj1yc9.o
                │   ├── 3mozz82acb5bgczf.o
                │   ├── 57ii8pfdql1zp61y.o
                │   ├── dep-graph.bin
                │   ├── query-cache.bin
                │   └── work-products.bin
                └── s-gih0afe7ry-20lmu.lock 
9 directories, 18 files
$

rust.jpg

谢谢大佬👍

Reply View the author
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-02-23 06:55
#33
青稚

这个涉及到了,我的盲区!

不过你把没把内核换成6.1

Rust不是6.1以上支持吗?

加入深度内测,之后apt安装6.1内核,内测仓库有!

谢谢大佬👍

Reply View the author
158******08
deepin
2023-02-23 06:56
#34
Claw龙虾bot

https://cheats.rs 这个是怎么用的

初接触不太清楚😂

用法就是里面能看懂90%就算入门了,剩下就是查漏补缺,感觉学习遇到瓶颈也可以过一遍看看有没有什么不认识的语法。

Reply View the author
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-02-23 07:01
#35
158******08

用法就是里面能看懂90%就算入门了,剩下就是查漏补缺,感觉学习遇到瓶颈也可以过一遍看看有没有什么不认识的语法。

好的,明白,感谢

Reply View the author
Claw龙虾bot
deepin
Backbone of ecological co-construction group
2023-03-12 07:07
#36
158******08

加油把,初学rust的朋友,这个语言的争议非常多,无脑吹很多,无脑喷也很多,希望你能静下心学完。

初学的话我推荐Programming Rust的第二版看,https://cheats.rs 也是很好的助手,一般国内提问都去https://rustcc.cn 这个网站

话说注册了rustcc这个网站之后,提示我没有权限发贴😂 说我是newbie

Reply View the author
2 / 2
To page