我有关于交叉编译的问题。
#include <stdio.h>
int main()
{
printf("hello\n");
return 0;
}
这是我用过的一个简单的hello world代码。
我正在使用arm-none-eabi-g ++,从导师图形下载。这是错误。 我不知道遗漏了哪些lib。
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol _start; defaulting to 00008018
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-abort.o): In function `abort':
abort.c:(.text+0x10): undefined reference to `_exit'
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text+0x1c): undefined reference to `_kill'
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text+0x44): undefined reference to `_getpid'
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0x18): undefined reference to `_sbrk'
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text+0x20): undefined reference to `_write'
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-closer.o): In function `_close_r':
closer.c:(.text+0x18): undefined reference to `_close'
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text+0x1c): undefined reference to `_fstat'
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text+0x18): undefined reference to `_isatty'
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-lseekr.o): In function `_lseek_r':
lseekr.c:(.text+0x20): undefined reference to `_lseek'
/home/kang/Utils/arm-2013.05/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/lib/libc.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text+0x20): undefined reference to `_read'
collect2: error: ld returned 1 exit status
这是编译器版本。
$ arm-linux-gnueabi-g ++ -v
使用内置规格。 COLLECT_GCC = /家庭/炕/的Utils /臂-2013.05 / bin中/臂-NONE-EABI-G ++ COLLECT_LTO_WRAPPER = /家庭/康/ utils的/ ARM-2013.05 / bin中/../的libexec / GCC / ARM-NONE-EABI / 4.7.3 / LTO-包装 目标:arm-none-eabi配置: /scratch/jbrown/2013.05-arm-eabi-release/src/gcc-4.7-2013.05/configure --build = i686-pc-linux-gnu --host = i686-pc-linux-gnu --target = arm-none-eabi --enable-threads --disable-libmudflap --disable-libssp --disable- libstdcxx-pch --enable-extra-sgxxlite-multilibs --with-gnu-as --with-gnu-ld --with-specs ='%{save-temps:-fverbose-asm} -D__CS_SOURCERYGXX_MAJ __ = 2013 -D__CS_SOURCERYGXX_MIN__ = 5 -D__CS_SOURCERYGXX_REV __ = 23%{O2:%{!fno-remove-local-statics:-fremove-local-statics}}%{O *:%{O | O0 | O1 | O2 | Os:;:%{ !FNO - 删除 - 本地静: -fremove-local-statics}}}' - enable-languages = c,c ++ --disable-shared --enable-lto --with-newlib --with-pkgversion ='Sourcery CodeBench Lite 2013.05-23' - with-bugurl = https://sourcery.mentor.com/GNUToolchain/ --disable-nls --prefix = / opt / codesourcery --with-headers = yes --with-sysroot = / opt / codesourcery / arm-none-eabi --with-build -sysroot = /刮伤/ jbrown / 2013.05臂-EABI释放/安装/臂-NONE-EABI --with-GMP = /刮伤/ jbrown / 2013.05臂-EABI释放/ OBJ / PKG-2013.05-23臂-NONE-EABI /臂2013.05-23臂-NONE-eabi.extras /主机库-i686-PC-Linux的GNU / USR --with-MPFR = /刮伤/ jbrown / 2013.05臂-EABI释放/ OBJ / PKG-2013.05-23臂-NONE-EABI /臂2013.05-23臂-NONE-eabi.extras /主机库-i686-PC-Linux的GNU / USR --with-MPC = /刮伤/ jbrown / 2013.05臂-EABI释放/ OBJ / PKG-2013.05-23臂-NONE-EABI /臂2013.05-23臂-NONE-eabi.extras /主机库-i686-PC-Linux的GNU / USR --with-PPL = /刮伤/ jbrown / 2013.05臂-EABI释放/ OBJ / PKG-2013.05-23臂-NONE-EABI /臂2013.05-23臂-NONE-eabi.extras /主机库-i686-PC-Linux的GNU / USR --with-host-libstdcxx =' - static-libgcc -Wl,-Bstatic,-lstdc ++, - Bdynamic -lm' - with-cloog = / scratch / jbrown / 2013.05-arm-eabi-release / obj / pkg- 2013.05-23臂-NONE-EABI /臂2013.05-23臂-NONE-eabi.extras /主机库-i686的-PC-Linux的GNU / USR --with-= libelf的/刮伤/ jbrown / 2013.05臂-EABI释放/ OBJ / PKG-2013.05-23臂-NONE-EABI /臂2013.05-23臂-NONE-eabi.extras /主机库-i686-PC-Linux的GNU / USR --disable-libgomp --disable-libitm --enable-poison-system-directories --with-build-time-tools = / scratch / jbrown / 2013.05-arm-eabi-release / install / arm-none-eabi /箱子 --with-集结时间的工具= /刮/ jbrown / 2013.05-ARM-EABI释放/安装/臂无 - EABI /箱 线程模型:单个gcc版本4.7.3(Sourcery CodeBench Lite 2013.05-23)
答案 0 :(得分:4)
您下载了错误的工具链。
arm-linux-gnueabi-g++
是使用arm-none-eabi
构建的,用于裸机程序。这不包含 libc ,即此工具链中不存在标准库(glibc或eglibc)。
因此,您需要下载arm-none-linux-gnueabi
工具链(即arm-2013.05-24-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
,而不是arm-2013.11-24-arm-none-eabi-i686-pc-linux-gnu.tar.bz2
)。
要验证上述内容,请键入:
cd /home/kang/Utils/arm-2013.05/arm-none-eabi
在这里,您只能找到bin include lib share
,而不会找到libc
目录。
下载arm-2013.05-24-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
;在这里,您将找到一个文件夹arm-2013.05/arm-none-linux-gnueabi/libc
。
您还可以通过以下方式进行验证:
arm-linux-eabi-g++ -print-sysroot and
arm-none-linux-gnueabi-g++ -print-sysroot
另请参阅上一个问题:how to work with external libraries when cross compiling?
答案 1 :(得分:1)
我正在使用arm-linux-gnueabi-g ++。它下载了导师图形。
这是错误的名字。您的所有输出都表明Mentor Graphics已打包 arm-none-gnueabi
工具链并错误地将其命名为arm-linux-gnueabi
(它甚至不符合命名约定)。
抱歉,我错误输入了我的编译器。我正在使用arm-none-eabi-g ++
获取arm-none-linux-gnueabi
工具链的版本(即定位GNU / Linux而不是EABI)。
这个将包含与Linux操作系统连接的GCC运行时。您现在缺少的所有功能都是该界面的一部分。