1

我正在做我的硕士论文,我在配置交叉编译器时遇到了问题。我已经阅读了很多文章、常见问题解答、教程等,但我仍然认为我遗漏了一些东西,可能非常愚蠢和基础,但没有这些,我就无法对所有事情有清晰的认识,我也不能让一切正常……所以请随时向我解释一切。让我们来解决问题。

我正在使用 SoClib 设计具有许多 MIPS 和许多 RAM 的 NoC,并且我想在每个 RAM 中加载不同的应用程序,以使每个 MIPS 仅从一个 RAM 读取。我设法使用非常简单的应用程序来做到这一点(比如带中断的 hello word……),所以现在我试图实现一个 JPEG 解码器,以便以更强烈的方式使用 MIPS。问题是我使用的交叉编译器找不到基本的 stdio 函数,因此无法为 mips 编译应用程序。所以基本上我没有设法安装一个工作完整的交叉编译器。

1)让我们从安装 SoClib 的交叉编译器开始:这里有我安装它的指南:http: //www.soclib.fr/trac/dev/wiki/CrossCompiler 现在从我已经阅读这不是一个完整的交叉编译器。我只安装了第一阶段 gcc,它可以为 mips 生成 elf 代码,但不能使用任何 C 函数。有了那个,我应该编译一个 C 库来创建一个新的交叉编译器。所以它不工作是正常的,尽管这并不能回答这个问题:为什么“Hello world”在使用 printf 并包含 stdio.h 的情况下工作?答案应该是我已经看到 SoClib 的头文件 stdio.h 实现了很少的功能(printf 在那里),所以我不能在那个编译器中使用标准 C 库。

2)因此,我决定安装一个完整的交叉编译器,并且我已经阅读了很多指南,因此我只会发布我在实践中使用过的两个: http ://www.cse.iitb.ac.in /grc/gcc-workshop-11/downloads/slides/gccw11-config-build.pdf 从第 108 页开始(在解释交叉编译的问题之前)它使用 EGLIBC。唯一的区别是我使用了“mipsel-elf”作为目标。如果我理解正确的话,这个方法需要一个 3 阶段的交叉编译器,因为 eglibc 不能用第一阶段的交叉编译器完全编译。现在的问题是我无法使用第一阶段交叉编译器成功安装 eglibc(它在第 122 页失败)。我附上了日志。我认为问题开始于它说:“mipsel-elf-gcc:错误:无法识别的选项'-V'”和“mipsel-elf-gcc:致命错误:没有输入文件编译终止”。似乎我的编译器有一些问题,并且所有都使用不受支持的平台完成......但它应该可以工作,因为我已经复制了 eglibc/ports 目录,就像指南所说的......</p>

3) 我尝试了另一个使用 newlib 而不是 eglibc 的指南: http://www(dot)cygwin(dot)com/ml/crossgcc/2005-08/msg00114/l-cross-ltr.pdf 本指南仅创建一个两阶段的交叉编译器。我认为这是因为 newlib 可以用第一阶段编译器完全编译……我说的对吗?无论如何,我遇到了同样的问题。我无法编译 newlib 并且收到类似的错误(附加日志)。

所以这是我的问题,在这里我提出了一些疑问,我试图解决它。

4) 问题可能出在目标 = mipsel-elf 上吗?我从 gnu 文档中知道配置 gnu 的名称应该是:cpu-manufacturer-os(或 cpu-manufacturer-kernel-os),但我读过 mipsel-elf 被接受。精灵应该是因为我不想在我的 NoC 平台上加载操作系统,这是第二个疑问……</p>

5)问题可能出在操作系统上吗?指南使用 linux 内核头文件……也许带有 mipsel-elf 目标我不应该配置 binutils –with-sysroot?但听起来我很奇怪......应该改变什么?

6) 还有一个可能很愚蠢的问题。stdio 和通常的 C 函数,不需要操作系统,对吗?因为所有这些问题都让我对基础产生怀疑……所以我应该能够使用 mipsel-elf 交叉编译器运行 JPEG 解码 C 应用程序,对吧?

我们将不胜感激每一个考虑、建议和帮助。如果您有关于这些论点的一些文件,请告诉我,我想学习并在这个领域变得更有信心。谢谢

eglibc 日志:

configure:2426: $? = 0
configure:2433: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc -v >&5
Using built-in specs.
COLLECT_GCC=/home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc
COLLECT_LTO_WRAPPER=/home/bertone/programmazione/crosscompiler/mips/install/libexec/gcc/mipsel-elf/4.6.2/lto-wrapper
Target: mipsel-elf
Configured with: ../../../../../Scaricati/src/gcc-4.6.2/configure --target=mipsel-elf --prefix=/home/bertone/programmazione/crosscompiler/mips/install --without-headers --with-newlib --disable-shared --disable-threads --disable-libssp --disable-libgomp --disable-libmudflap --enable-languages=c --disable-werror
Thread model: single
gcc version 4.6.2 (GCC) 
configure:2437: $? = 0
configure:2444: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc -V >&5
mipsel-elf-gcc: error: unrecognized option '-V'
mipsel-elf-gcc: fatal error: no input files
compilation terminated.
configure:2448: $? = 1
configure:2452: checking for suffix of object files
configure:2478: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc -c   conftest.c >&5
configure:2482: $? = 0
configure:2507: result: o
configure:2511: checking whether we are using the GNU C compiler
configure:2540: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc -c   conftest.c >&5
configure:2547: $? = 0
configure:2564: result: yes
configure:2573: checking whether /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc accepts -g
configure:2603: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc -c -g  conftest.c >&5
configure:2610: $? = 0
configure:2711: result: yes
configure:2728: checking for /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc option to accept ISO C89
configure:2802: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc  -c -g -O2  conftest.c >&5
conftest.c:9:19: fatal error: stdio.h: No such file or directory
compilation terminated.
configure:2809: $? = 1
configure: failed program was:
| /* confdefs.h.  */
| #define PACKAGE_NAME "GNU C Library"
| #define PACKAGE_TARNAME "glibc"
| #define PACKAGE_VERSION "(see version.h)"
| #define PACKAGE_STRING "GNU C Library (see version.h)"
| #define PACKAGE_BUGREPORT "http://sourceware.org/bugzilla/"
| /* end confdefs.h.  */
| #include <stdarg.h>
| #include <stdio.h>
| #include <sys/types.h>
| #include <sys/stat.h>
| /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
| struct buf { int x; };
| FILE * (*rcsopen) (struct buf *, struct stat *, int);
| static char *e (p, i)
|      char **p;
|      int i;
| {
|   return p[i];
| }
| static char *f (char * (*g) (char **, int), char **p, ...)
| {
|   char *s;
|   va_list v;
|   va_start (v,p);
|   s = g (p, va_arg (v,int));
|   va_end (v);
|   return s;
| }
| 
| /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
|    function prototypes and stuff, but not '\xHH' hex character constants.
|    These don't provoke an error unfortunately, instead are silently treated
|    as 'x'.  The following induces an error, until -std is added to get
|    proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
|    array size at least.  It's necessary to write '\x00'==0 to get something
|    that's true only with -std.  */
| int osf4_cc_array ['\x00' == 0 ? 1 : -1];
| 
| /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
|    inside strings and character constants.  */
| #define FOO(x) 'x'
| int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
| 
| int test (int i, double x);
| struct s1 {int (*f) (int a);};
| struct s2 {int (*f) (double a);};
| int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
| int argc;
| char **argv;
| int
| main ()
| {
| return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
|   ;
|   return 0;
| }
configure:2802: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc -qlanglvl=extc89 -c -g -O2  conftest.c >&5
mipsel-elf-gcc: error: unrecognized

选项“-qlanglvl=extc89”配置:2809:$?= 1

NEWLIB日志

configure:4049: $? = 0
configure:4038: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc -v >&5
Using built-in specs.
COLLECT_GCC=/home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc
COLLECT_LTO_WRAPPER=/home/bertone/programmazione/crosscompiler/mips/install/libexec/gcc/mipsel-elf/4.6.2/lto-wrapper
Target: mipsel-elf
Configured with: ../../../../../Scaricati/src/gcc-4.6.2/configure --target=mipsel-elf --prefix=/home/bertone/programmazione/crosscompiler/mips/install --without-headers --with-newlib --disable-shared --disable-threads --disable-libssp --disable-libgomp --disable-libmudflap --enable-languages=c --disable-werror
Thread model: single
gcc version 4.6.2 (GCC) 
configure:4049: $? = 0
configure:4038: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc -V >&5
mipsel-elf-gcc: error: unrecognized option '-V'
mipsel-elf-gcc: fatal error: no input files
compilation terminated.
configure:4049: $? = 1
configure:4038: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc -qversion >&5
mipsel-elf-gcc: error: unrecognized option '-qversion'
mipsel-elf-gcc: fatal error: no input files
compilation terminated.
configure:4049: $? = 1
configure:4069: checking for C compiler default output file name
configure:4091: /home/bertone/programmazione/crosscompiler/mips/install/bin/mipsel-elf-gcc    conftest.c  >&5
/home/bertone/programmazione/crosscompiler/mips/install/lib/gcc/mipsel-elf/4.6.2/../../../../mipsel-elf/bin/ld: cannot find crti.o: No such file or directory
/home/bertone/programmazione/crosscompiler/mips/install/lib/gcc/mipsel-elf/4.6.2/../../../../mipsel-elf/bin/ld: cannot find crtbegin.o: No such file or directory
/home/bertone/programmazione/crosscompiler/mips/install/lib/gcc/mipsel-elf/4.6.2/../../../../mipsel-elf/bin/ld: cannot find -lgcc
/home/bertone/programmazione/crosscompiler/mips/install/lib/gcc/mipsel-elf/4.6.2/../../../../mipsel-elf/bin/ld: cannot find -lgcc
/home/bertone/programmazione/crosscompiler/mips/install/lib/gcc/mipsel-elf/4.6.2/../../../../mipsel-elf/bin/ld: cannot find crtend.o: No such file or directory
/home/bertone/programmazione/crosscompiler/mips/install/lib/gcc/mipsel-elf/4.6.2/../../../../mipsel-elf/bin/ld: cannot find crtn.o: No such file or directory
collect2: ld returned 1 exit status
configure:4095: $? = 1
configure:4132: result: 
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:4138: error: in `/home/bertone/programmazione/crosscompiler/mips/build/newlib':
configure:4142: error: C compiler cannot create executables
4

2 回答 2

0

为什么不直接下载用于 MIPS 的免费预构建 GCC Codesourcery Lite交叉编译器工具链?

6) stdio 和通常的 C 函数,不需要操作系统吗?

通常,libc 将 stdio 调用转换为对底层操作系统的系统调用,因此您需要一个操作系统才能使 stdio 工作。如果您的 JPEG 解码器应用程序不调用任何需要操作系统的东西,它就可以正常工作,但是您需要创建一个方法来从您的 NoC 上的每个单独的 CPU 到外部世界获取结果。

于 2012-01-06T21:38:08.083 回答
0

首先,关,你需要这些stdio函数吗?

你能替换这些 stdio 函数吗?例如,您是否真的需要 printf(其中一个更痛苦的),或者您是否愿意用其他东西替换它们,也许是 string_display() 和 hex_display() 函数,它们可能很容易实现和库和系统无关。

这些是文件 I/O 功能吗?我似乎记得一个流行的开源 jpeg 解码器想要为你做文件 I/O。实现一个 fopen() (只返回任何有效的东西),一个 fread ,它只是跟踪您包含在二进制文件中的一些 const 数据中的指针,并执行 mem 复制和 fwrite,这真的很难deal 跟踪数组中的指针并进行 mem 复制。

我已经嵌入了 jpeg 解码器、mp3 等进行系统调用,两者都通过使用 newlib() 这使它更容易一些,但是现在构建交叉编译器非常痛苦,并且用不同的函数替换系统调用或通过实现这些功能的模拟。

如果您使用免费的 codesourcery lite(现在称为 codebench 或其他东西,因为它是指导图形而不是 codesourcery)并用模拟的系统调用替换系统调用,您就不必再弄乱编译器了。

我有一些非常简单的 mips 代码,还有一些关于构建我正在谈论的 gnu 交叉编译器的说明(如果你不使用系统调用、C 库调用、gcc 库调用,因为你自己实现了所有东西,那就太好了) .

https://github.com/dwelch67/pic32_samples

从我正在构建的东西到完整的交叉编译器并不遥远。Gcc/gnu 不太稳定,您可以交叉编译任何版本的任何版本并让它工作,同样,使用任何版本的任何主机上任何版本的任何目标的交叉编译器都不稳定。有时,针对某个目标的 binutils+gcc+newlib 版本恰好可以正常工作。例如,在这段时间/历史上,这在 linux 和 windows 上的 mingw 上都有效。

http://www.dwelch.com/ipod/gccarm.txt

但是除非您使用虚拟机(vmware 等)并在其上安装具有足够旧构建系统的旧 linux,否则您将无法构建上述内容。

不久前,也许这仍然适用于现代系统。它适用于手臂,但也许它也适用于 mips。

http://www.cowlark.com/2009-07-04-building-gcc/

我认为我没有在没有系统调用或模拟系统调用的情况下使用 mp3 和 zlib 和 jpeg 库发布的任何代码在我可以发布它们的地方。如果您想将 zlib 用作性能测试或其他东西,一次压缩或解压缩或两者兼而有之,则 malloc 很容易实现 zlib 之类的东西,不是通用的东西,而是一个具有数据输入和数据输出的受控测试环境。其他受控环境 jpeg 编码或解码、mp3 编码或解码也是如此(它们是有损的,因此您无法将输入与输出进行比较以验证系统产生了正确的结果,尽管与已知的良好系统相比,校验和或 crc 很容易/结果)。

如果您检查 newlib 中我清空并稍后替换的文件,您可以看到 newlib 将 stdio 调用归结为什么,然后您将实现这些功能中的每一个。我有几个旧站点至少有 dhrystone 示例,它们几乎只需要 printf http://www.dwelch.com/ipod/ http://www.dwelch.com/gba/dhry.htm 你可以在哪里看看我对 newlib 函数做了什么,主要是通过返回一个传递值来中和它们,并弄清楚 newlib 在它想要输出到标准输出时做了什么。

或者用备用函数替换一些 stdio 调用的示例,导致某些东西仍然有效。不是说它很漂亮,但你可以玩游戏。 https://github.com/dwelch67/stm32f4d/blob/master/adventure/

Basically what I am reading is that you have identified a problem but are only pursuing one path, solving it on the compiler side. When you could be solving it by creating an abstraction layer or shim, or by removing the offending code completely or replacing it with less offensive code. If you look at the source code for adventure above and similar era games empire, etc, even small c compilers and other code that has been ported a number of times, you can see they did exactly that, they solved the problem by making non-language, non-system specific calls in the bulk of the code, and then the last mile was to implement those calls in one or a few system specific places. Even if you were to get a gcc+newlib or gcc+glibc cross compiler you are still going to have to replace the default stdio to operating system layer with your own. (that is what the compiler side of this is as well, a large bulky abstraction layer, glibc, newlib, etc, that you still have to implement the backend).

于 2012-01-11T02:26:02.430 回答