【问题标题】:Static executable compiling error : undefined reference to静态可执行文件编译错误:未定义的引用
【发布时间】: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 function main': /data/a/ts /test.c:2: 对printf' collect2: ld returned 1 exit status的未定义引用
  • Static linking glibc的可能重复
  • @alk,我的问题与您提到的链接中的问题没有任何相似之处!

标签: c linux arm


【解决方案1】:

首先,查看 libc.a。看起来它应该在 /system/android-gcc-4.4.0/sysroot/usr/lib/ 中。 所以你需要执行:

nm /system/android-gcc-4.4.0/sysroot/usr/lib/libc.a | grep printf

如果存在 printf,则说明链接参数有问题。可以通过在 gcc 命令行中添加标志 -v 来验证。仔细检查输出以了解 libc 链接的确切内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-30
    • 2017-03-29
    • 2018-04-19
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 2013-12-25
    相关资源
    最近更新 更多