【发布时间】:2013-10-20 16:06:12
【问题描述】:
我正在尝试使用完整且稳定的 GCC 4.4.0 编译一个简单的“hello world”程序。当我尝试编译动态可执行文件时,一切正常,但是当我尝试编译静态可执行文件时,出现错误“未定义对 printf 的引用”。我尝试在静态模式下编译的每个程序都是一样的。它无法识别 libc 函数。即使使用“-nostdlib”或“-lc”也是一样的! “-L ${LD_LIBRARY_PATH}”也不能修复它。
./ccL10382.o: In function `main':
test.c:(.text+0x4): undefined reference to `printf'
collect2: ld returned 1 exit status
我该怎么办?
【问题讨论】:
-
有/没有
-nostdlib我得到了同样的错误 -
我猜 -static 选项对你不起作用,是吗?
gcc -Wall -static -g -o test test.c -
# gcc -Wall -static -g -o test test.c test.c:2: warning: return type of 'main' is not 'int' /system/android-gcc-4.4.0/sysroot/usr/lib/crtbegin_dynamic.o: In function_start': bionic/libc/arch-arm/bionic/crtbegin_dynamic.S:(.text+0x10): undefined reference to__libc_init' ./ccx11630.o: In functionmain': /data/a/ts /test.c:2: 对printf' collect2: ld returned 1 exit status的未定义引用 -
Static linking glibc的可能重复
-
@alk,我的问题与您提到的链接中的问题没有任何相似之处!