我正在开发一个应该在Android系统启动期间运行的简单可执行文件。它使用一个小tinydir.h库来浏览特定目录中的文件。即使它为x86和x86_64(在OS X上使用gcc)编译得很好,当我尝试使用Android系统本身(对于ARM)构建它时,我得到以下输出:
target StaticExecutable: preparefs (out/target/product/hammerhead/obj/EXECUTABLES/preparefs_intermediates/LINKED/preparefs)
out/target/product/hammerhead/obj/lib/crtbegin_static.o:crtbrand.c:function _start: error: undefined reference to '__libc_init'
out/target/product/hammerhead/obj/lib/crtbegin_static.o:crtbrand.c:function atexit: error: undefined reference to '__cxa_atexit'
bionic/libc/include/string.h:178: error: undefined reference to 'memset'
system/core/preparefs/tinydir.h:262: error: undefined reference to 'free'
system/core/preparefs/tinydir.h:274: error: undefined reference to 'closedir'
system/core/preparefs/tinydir.h:286: error: undefined reference to '__errno'
system/core/preparefs/tinydir.h:291: error: undefined reference to '__errno'
system/core/preparefs/tinydir.h:298: error: undefined reference to 'readdir'
system/core/preparefs/main.c:23: error: undefined reference to 'malloc'
system/core/preparefs/main.c:61: error: undefined reference to 'memcpy'
system/core/preparefs/main.c:64: error: undefined reference to 'system'
bionic/libc/include/string.h:121: error: undefined reference to 'strcpy'
system/core/preparefs/tinydir.h:160: error: undefined reference to 'opendir'
system/core/preparefs/tinydir.h:164: error: undefined reference to '__errno'
system/core/preparefs/tinydir.h:171: error: undefined reference to 'readdir'
system/core/preparefs/tinydir.h:331: error: undefined reference to '__errno'
system/core/preparefs/main.c:75: error: undefined reference to 'strcmp'
bionic/libc/include/string.h:238: error: undefined reference to '__strlen_chk'
bionic/libc/include/string.h:229: error: undefined reference to 'strlen'
bionic/libc/include/string.h:121: error: undefined reference to '__strcpy_chk'
bionic/libc/include/string.h:168: error: undefined reference to '__strcat_chk'
bionic/libc/include/string.h:121: error: undefined reference to '__strcpy_chk'
bionic/libc/include/string.h:168: error: undefined reference to '__strcat_chk'
system/core/preparefs/tinydir.h:371: error: undefined reference to 'stat'
bionic/libc/include/string.h:276: error: undefined reference to '__strrchr_chk'
bionic/libc/include/string.h:238: error: undefined reference to '__strlen_chk'
system/core/preparefs/main.c:75: error: undefined reference to 'strcmp'
system/core/preparefs/main.c:82: error: undefined reference to 'system'
system/core/preparefs/main.c:85: error: undefined reference to 'system'
bionic/libc/include/string.h:121: error: undefined reference to 'strcpy'
bionic/libc/include/string.h:168: error: undefined reference to '__strcat_chk'
bionic/libc/include/string.h:168: error: undefined reference to '__strcat_chk'
system/core/preparefs/main.c:90: error: undefined reference to 'system'
system/core/preparefs/main.c:92: error: undefined reference to 'fopen'
system/core/preparefs/main.c:94: error: undefined reference to 'fseek'
system/core/preparefs/main.c:95: error: undefined reference to 'ftell'
system/core/preparefs/main.c:96: error: undefined reference to 'fclose'
system/core/preparefs/main.c:98: error: undefined reference to 'fopen'
system/core/preparefs/main.c:99: error: undefined reference to 'malloc'
system/core/preparefs/main.c:100: error: undefined reference to 'fread'
system/core/preparefs/main.c:101: error: undefined reference to 'fclose'
bionic/libc/include/string.h:238: error: undefined reference to '__strlen_chk'
system/core/preparefs/main.c:113: error: undefined reference to 'strcmp'
system/core/preparefs/main.c:129: error: undefined reference to 'time'
bionic/libc/include/stdio.h:387: error: undefined reference to 'snprintf'
bionic/libc/include/string.h:121: error: undefined reference to 'strcpy'
system/core/preparefs/main.c:140: error: undefined reference to '__stack_chk_fail'
system/core/preparefs/main.c:140: error: undefined reference to '__stack_chk_guard'
/tmp/AOSP-toolchain/build/../gcc/gcc-4.8/libgcc/unwind-arm-common.inc:289: error: undefined reference to 'abort'
/tmp/AOSP-toolchain/build/../gcc/gcc-4.8/libgcc/unwind-arm-common.inc:346: error: undefined reference to 'memcpy'
/tmp/AOSP-toolchain/build/../gcc/gcc
-4.8/libgcc/unwind-arm-common.inc:376: error: undefined reference to 'memcpy'
/tmp/AOSP-toolchain/build/../gcc/gcc-4.8/libgcc/unwind-arm-common.inc:505: error: undefined reference to 'abort'
/tmp/AOSP-toolchain/build/../gcc/gcc-4.8/libgcc/config/arm/pr-support.c:378: error: undefined reference to 'abort'
/tmp/AOSP-toolchain/build/../gcc/gcc-4.8/libgcc/config/arm/pr-support.c:384: error: undefined reference to 'abort'
collect2: error: ld returned 1 exit status
make: *** [out/target/product/hammerhead/obj/EXECUTABLES/preparefs_intermediates/LINKED/preparefs] Error 1
#### make failed to build some targets (06:00 (mm:ss)) ####
这是我使用的Android.mk文件:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= preparefs
LOCAL_SRC_FILES := main.c
LOCAL_CFLAGS += -std=gnu99 -Wl,--start-group -lgcc -lc -lm -lrdimon -Wl,--end-group -fsigned-char -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_EXECUTABLE)
include $(call first-makefiles-under,$(LOCAL_PATH))
关于如何构建它的任何想法?
提前致谢!
- 编辑: 这是main.c文件的剥离版本,您可以使用它来重现该问题:
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <tinydir.h>
#include <time.h> // don't mind the unnecessary imports, I removed some code to provide this sample
int main(void) {
tinydir_dir dir;
tinydir_open(&dir, "/directory");
while (dir.has_next)
{
tinydir_file file;
tinydir_readfile(&dir, &file);
if(strcmp(file.name, ".") == 0 || strcmp(file.name, "..") == 0)
{
tinydir_next(&dir);
continue;
}
if (file.is_dir)
{
return 1;
}
//doing something about the file
tinydir_next(&dir);
}
tinydir_close(&dir);
return 0;
}
答案 0 :(得分:0)
这些函数是libc的一部分,它位于arm工具链的目录中。可能你的手臂工具链配置不正确。检查你的工具链目录并确保libc.so确实存在,然后执行nm -g libc.a
(使用nm的arm交叉编译版本,而不是主机版本)。如果函数不存在,则可能必须使用适当的选项重新配置/重新编译工具链。如果他们在那里,你必须确保你试图链接到该库。