错误:找不到链接器“x86_64-w64-mingw32-gcc”
我正在使用 MacOS Big Sur,并且我正在尝试交叉编译到 Windows,但问题是,这个“错误:找不到链接器 x86_64-w64-mingw32-gcc
” 阻止我这样做,这是我的货物依赖项:
[dependencies]
rand = "0.8.4"
macroquad = "0.3.13"
perlin_rust = "0.1.0"
libm = "0.2.2"
我尝试过 Cargo Clean/Update,并且尝试过 mvsc 而不是 gnu
I am using MacOS Big Sur, and i am trying to cross compile to windows, but the problem is, this "error: linker x86_64-w64-mingw32-gcc
not found" prevents me from doing that, here are my cargo dependencies:
[dependencies]
rand = "0.8.4"
macroquad = "0.3.13"
perlin_rust = "0.1.0"
libm = "0.2.2"
I have tried Cargo Clean/Update, and I have tried mvsc instead of gnu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TLDR;
除了使用 rustup 安装交叉目标之外,您还需要安装一个实际的交叉链接器并使用 Cargo 配置文件或环境变量告诉 Cargo
它似乎您正在尝试交叉编译您的包。
您可以在这里阅读有关交叉编译的更多信息;
简而言之,编译器是一个程序,它获取文本源代码并生成操作系统和 CPU 可以理解的内容。
当您为正在开发的平台构建软件时,一切都很好。您拥有所有工具,但是当您想要针对另一个平台或操作系统时,您需要一个编译器,该编译器是为在您的计算机上工作而生成的,但输出应该在目标平台/操作系统上工作的二进制文件。
因此,在您的情况下,您需要安装适用于 mingw 目标的 mac 的交叉工具链,因为 rust 本身没有交叉链接器。一旦你获得了交叉工具链,你所需要做的就是告诉 Cargo 如何找到它。
这里是一个旨在使交叉编译不那么痛苦的项目。
我还强烈建议您阅读货运手册
在这里您可以看到告诉货物有关交联剂的方法之一
另一种方法是使用环境变量(我更喜欢它并且更容易与 makefile 一起使用)
下面你可以看到我的 makefile 中的一个示例
再次cargo book引用了它
总体而言,交叉编译很痛苦,我花了相当长的时间来理解它的机制,但这是值得的,而不是复制粘贴我在博客上找到的命令。
我还觉得它缺乏严格的文档。 Cargo 书没有告诉你任何关于寻找链接器的事情,假设你已经知道这一点,并且图片交叉编译就像在使用 rustup 安装目标工具链后开箱即用的东西。
TLDR;
Besides installing a cross target with rustup you need to install an actual cross linker and tell cargo about it using cargo config file or an environment variable
It seems you are attempting to cross compile your package.
you can read here more about cross compilation;
In a nutshell compiler is a program that takes your text source code and produces something the your operating system and cpu can understand.
When you are building software for the platform you are developing on, it's all nice. You have all the tools but when you want to target another platform or os, you need a compiler that is produced to work on your machine but outputs a binary that is supposed to work on the target platform/os.
So, In your case you need to install a cross toolchain that for mac for mingw target because rust does not have a cross linker itself. Once you get a cross toolchain all you need to do is to tell cargo how to find it.
Here is a project aims to make cross compilation less painful.
I also strongly advise you to read the cargo book
here you can see one of the ways of telling cargo about the cross linker
another way is to use an environment variable (which I like better and easier to use with makefiles)
and below you can see an example of that from one of my makefiles
and Again the cargo book refers to it
Overall cross compiling is painful it took me quite some time to understand the mechanics of it but it was worth it instead of copy pasting commands I found on the blogs.
I also feel like it lacks severe documentation. Cargo book doesn't tell you anything about finding a linker assumes you know this already and pictures cross compiling as something just work out of box after installing a target toolchain with rustup.
对于在 MacOS 上工作的用户(安装 MacPorts 后):
对于在 Ubuntu 上遇到相同问题的用户:
这应该可以解决你的问题。交叉编译器不是由 rustup 安装的,因此必须单独安装。
For those who work on MacOS (after installing MacPorts) :
For those who have the same problem on Ubuntu:
This should solve your issue. The cross compiler is not installed by rustup and thus must be installed separately.
我也遇到了同样的问题,原因是我的项目目录中有特殊字符。例如重音 á、í 等。
所以我将它们更改为常规字符,问题就不再出现了。
I had the same problem, the reason was that there were special characters in the directory where I had the project. such as accents á, í, etc.
So I changed them for regular characters and the problem stopped showing.