[英]Static executable compiling error : undefined reference to
I am trying to compile a simple "hello world" program using a complete and stable GCC 4.4.0. 我正在尝试使用完整且稳定的GCC 4.4.0编译一个简单的“ hello world”程序。 Every thing is OK when I try to compile a dynamic executable but when I try to compile the static executable one, I get error "undefined reference to printf".
当我尝试编译动态可执行文件时,一切正常,但是当我尝试编译静态可执行文件时,出现错误“未定义对printf的引用”。 It's the same in every program I try to compile in static mode.
我尝试在静态模式下编译的每个程序都一样。 It can not recognize libc functions.
它无法识别libc函数。 Even with "
-nostdlib
" or " -lc
" it's the same! 即使使用“
-nostdlib
”或“ -lc
”也是如此! Also " -L ${LD_LIBRARY_PATH}
" does not fix it. 另外,“
-L ${LD_LIBRARY_PATH}
”也无法解决。
./ccL10382.o: In function `main':
test.c:(.text+0x4): undefined reference to `printf'
collect2: ld returned 1 exit status
What should I do? 我该怎么办?
At the first, look into libc.a. 首先,查看libc.a。 Looks like it should be in /system/android-gcc-4.4.0/sysroot/usr/lib/.
看起来它应该在/system/android-gcc-4.4.0/sysroot/usr/lib/中。 So you need to execute:
因此,您需要执行:
nm /system/android-gcc-4.4.0/sysroot/usr/lib/libc.a | nm /system/android-gcc-4.4.0/sysroot/usr/lib/libc.a | grep printf
grep printf
If printf is present, you have a problem with link parameters. 如果存在printf,则链接参数有问题。 It can be verified by adding flag -v to gcc command line.
可以通过在gcc命令行中添加标志-v来进行验证。 Check output carefully to know what the libc links exactly.
仔细检查输出,以了解libc确切链接的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.