c - 静态可执行文件编译错误: undefined reference to

标签 c linux arm

我正在尝试使用完整且稳定的 GCC 4.4.0 编译一个简单的“hello world”程序。当我尝试编译动态可执行文件时,一切正常,但当我尝试编译静态可执行文件时,出现错误“对 printf 的 undefined reference ”。我尝试以静态模式编译的每个程序都是一样的。它无法识别 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

我应该做什么?

最佳答案

首先,查看 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 到底链接了什么。

关于c - 静态可执行文件编译错误: undefined reference to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19479596/

相关文章:

c - 缺少 locale_t

c - 为什么中断服务程序PUSH {r3,r4,r5,lr}但POP {r0,r4,r5,lr}会导致ERROR?

linux - 在 bash 文件中运行多个查找和 sed

c - snprintf() 使用 newlib nano 打印垃圾 float

linux - linux (arm) 中的 GPIO pin 中断处理程序

c - 使用 fgetc 将数据加载到二维数组中?

c++ - 使用 Swift 将 MergeCom DICOM 工具包包含在 ios 中

c - 为什么在同一地址空间的两个不同指针上调用 malloc?

linux - 如何在 TUI 中清除 gdb 中的控制台

linux - 在嵌入式 Linux 平台上将 libc 与 JNI 代码链接 (GuruPlug)