C语言 为 Mips 架构编译 C

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17006843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:38:22  来源:igfitidea点击:

Compile C for Mips architecture

cgcccompiler-errorsmipscross-compiling

提问by Qndel

I have seen several ways to do this (and so far I havent tried a couple but I want to isolate this one for ease)

我已经看到了几种方法来做到这一点(到目前为止我还没有尝试过几种,但我想轻松地隔离这个)

There is supposed to be a way to do this VIA gcc and I would prefer this i just keep hitting walls.

应该有一种方法可以通过 VIA gcc 来执行此操作,我更喜欢这样,我只是不断地撞墙。

I am using debian7 and can use what ever other flavor out there (I am for the time being wanting to avoid qemu casue I want something smaller scale.) I am following this example found here.

我正在使用 debian7 并且可以使用任何其他风格(我暂时想避免 qemu casue 我想要更小规模的东西。)我正在关注这里找到的这个例子。

http://moozing.wordpress.com/2011/04/05/cross-compile-in-debian/

http://moozing.wordpress.com/2011/04/05/cross-compile-in-debian/

I have been able to do everything and during part of this I had to install libgmp3c2-dummy_1.0_all.deb for ti to continue

我已经能够做所有事情,在此期间我必须安装 libgmp3c2-dummy_1.0_all.deb 以便 ti 继续

just now I need to compile and all I am compiling is a simple hello world script however , upon compiling I can't cause libgmp.so.3 is not in the /usr/lib/ dir however, there is one in /usr/lib/mips-linux-gnu-gcc folder I thought I'd copy it over to see if get it to compile and I get that this elf file is encoded in big-endian which makes sense. but what is it that I am missing to compile this file??

刚才我需要编译,我正在编译的只是一个简单的 hello world 脚本,但是,在编译时我不能导致 libgmp.so.3 不在 /usr/lib/ 目录中,但是 /usr/ 目录中有一个lib/mips-linux-gnu-gcc 文件夹我想我会把它复制过来看看是否让它编译,我知道这个 elf 文件是用大端编码的,这是有道理的。但是我缺少编译这个文件的原因是什么??

and I tried to compile the thing as big endian I think that either that I have confusion from the libraries or that I need a differnt libgmp.so.3 ..

我试图将这个东西编译为大端,我认为要么我对库感到困惑,要么我需要一个不同的 libgmp.so.3 ..

also I tried apt-get install libgmp-dev libgmp3-dev too.

我也试过 apt-get install libgmp-dev libgmp3-dev 。

Thank you for helping helping if you can! :) and if you know of a simple way to do this that wont take a bunch of space on the my machine then I am open but I would like to try with GCC and using the tool chain.

如果可以的话,感谢您的帮助!:) 并且如果您知道一种简单的方法来执行此操作并且不会在我的机器上占用大量空间,那么我是开放的,但我想尝试使用 GCC 并使用工具链。

Thanks!

谢谢!

回答by Qndel

Well I managed to compile MIPS in Debian. Edit I want to improve this answer for ease for use to others...

好吧,我设法在 Debian 中编译了 MIPS。编辑我想改进这个答案以方便其他人使用...

    1. deb http://www.emdebian.org/debian stable main to /etc/apt/sources.list 

    2. apt-get update.

    3. install libgmp3c2 from https://packages.debian.org/squeeze/libgmp3c2

    4. apt-get install gcc-4.3-mips-linux-gnu libgmp3c2-mips-cross this worked

then just mips-linux-gnu-gcc file.c -o executable

然后只是 mips-linux-gnu-gcc file.c -o 可执行文件

That's it.

就是这样。

PS if you're working on Routers.... use the -static option when compiling. So in the end it looked like

PS,如果您正在使用路由器.... 编译时使用 -static 选项。所以最后它看起来像

mips-linux-gnu-gcc -EB -march=34kc -static test.c -o test

If you have problems with a keyring public key not being recognized, use the emdebian-archive-keyringpackage which can be installed using apt.

如果您遇到无法识别密钥环公钥的问题,请使用emdebian-archive-keyring可以使用 apt 安装的软件包。

回答by markgz

Why not just install the free Mentor/Codesourcerygcc MIPS cross compiler, instead of trying to build one from scratch?

为什么不安装免费的Mentor/Codesourcerygcc MIPS 交叉编译器,而不是尝试从头开始构建?

When you have a MIPS cross compiler installed, you should install MIPS libraries in the appropriate directory for the cross compiler, and notin the /usr/libdirectory for your host linux installation. You cannot use apt-getto attempt to install MIPS libraries, since that tool can only install libraries for your host linux installation.

当你有一个MIPS交叉编译器安装,你应该安装MIPS库中的交叉编译相应的目录,而不是/usr/lib你的Linux主机的安装目录。您不能apt-get尝试安装 MIPS 库,因为该工具只能为您的主机 linux 安装安装库。

回答by wazy

You can reference this post Setting up cross-compiler for MIPS-I version 1since it seems to be the simplest solution to your problem since you want to simply cross-compile for MIPS (reference his answer to the question as well). Note I haven't actually tested it.

您可以参考这篇文章为 MIPS-I 版本 1 设置交叉编译器,因为它似乎是您问题的最简单解决方案,因为您只想为 MIPS 进行交叉编译(也参考他对问题的回答)。注意我还没有真正测试过它。

I have built GCC to show the source in MIPS assembly from my ARM processor, but I can't seem to find the guide anymore. But you may want to look into building gcc for cross-compiling as well. I'll update this post in a few days since this has intrigued me to write a simple HOWTO set up a MIPS cross-compiler.

我已经构建了 GCC 来显示来自我的 ARM 处理器的 MIPS 程序集中的源代码,但我似乎再也找不到该指南了。但是您可能还想考虑构建 gcc 以进行交叉编译。我将在几天后更新这篇文章,因为这促使我编写一个简单的 HOWTO 设置 MIPS 交叉编译器。