简体   繁体   English

静态可执行编译错误:未定义引用

[英]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.

相关问题 使用C编译静态库时出现“未定义引用”错误 - “undefined reference” error compiling a static library in C 编译时出错“未定义引用`sin'”(使用-lm) - Error “undefined reference to `sin'” when compiling (with -lm) 使用libjpeg未定义参考错误编译C代码 - compiling C code with libjpeg undefined reference error Littlecms-编译“对“ cmsOpenProfileFromFile”的未定义引用”时出错 - Littlecms - error during compiling “undefined reference to `cmsOpenProfileFromFile' ” 编译错误 GCC Ubuntu: undefined reference to - Error compiling GCC Ubuntu : undefined reference to C编译 - “未定义引用”? - C compiling - “undefined reference to”? 在构建可执行文件时涉及 .so 库时对错误的未定义引用 - Undefined reference to error when .so libraries are involved while building the executable 使用GNU GCC编译器编译C项目时出现“未定义的引用”错误 - “undefined reference to ” error when compiling C project with GNU GCC Compiler 使用gcc编译时Tcl解释器未定义参考错误 - Tcl interpreter undefined reference error while compiling with gcc 编译汇编文件时出现问题 - 错误:对`function name'的未定义引用 - Problems compiling assembly file - Error: undefined reference to `function name'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM