gcc使用newlib而不是glibc?

时间:2011-04-21 19:59:47

标签: gcc newlib

我想使用newlib而不是glibc来编译小的静态二进制文件。 (我不打算交叉编译,因为二进制文件将由同一台计算机使用。)我相信我需要为此编译一个单独的gcc?

我编译了gcc:

./configure --prefix=/home/myuser/Desktop/gcc-4.4.5 --libexecdir=/home/myuser/Desktop/gcc-4.4.5 --libdir=/home/myuser/Desktop/gcc-4.4.5 --with-gxx-include-dir=/home/myuser/Desktop/gcc-4.4.5 --enable-languages=c --enable-libmudflap --disable-multilib --disable-libssp --disable-nls --with-newlib --with-gnu-as --with-gnu-ld --with-system-zlib
make

它编译时没有错误,但现在我尝试编译一个简单的Hello World!程序它想要使用来自/ usr的头文件而不是我上面指定的路径。这些是一些错误:

In file included from /home/myprogram/Desktop/myprogram.c:1:
/usr/include/stdio.h:34:21: error: stddef.h: No such file or directory
In file included from /usr/include/stdio.h:75,
                 from /home/myprogram/Desktop/myprogram.c:1:
/usr/include/libio.h:53:21: error: stdarg.h: No such file or directory
In file included from /usr/include/stdio.h:75,
                 from /home/myprogram/Desktop/myprogram.c:1:
/usr/include/libio.h:332: error: expected specifier-qualifier-list before 'size_t'
/usr/include/libio.h:364: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/libio.h:373: error: expected declaration specifiers or '...' before 'size_t'

我做错了什么?编译一个新的gcc是必要的还是我可以使用我现有的gcc并使用newlib而不是glibc ???

3 个答案:

答案 0 :(得分:6)

你不需要为此重建gcc;你只需要将你现有的gcc指向正确的东西(使用-I-L等。)告诉它不要拉入常用的系统内容(使用{{1 }})。

newlib README file中标题为“共享newlib”的部分具有在本地编译时用于构建和链接共享或静态newlib的符文。

答案 1 :(得分:3)

我强烈建议使用crosstool-ng来构建您的GCC工具链。如果选择x86后跟“裸机”作为操作系统,则可以安全地使用newlib作为libc。

请注意,newlib 与操作系统一起工作 - 这是标准的东西,比如IO,不会开箱即用。

答案 2 :(得分:1)

您必须告诉编译器它可以在哪里找到包含文件:

gcc -IyourDirectoryHere -IanotherDirectoryHere

-I (这是一个减号,后面是意大利的首都)

更多详情:http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Directory-Options.html

HTH

马里奥

相关问题