1

我正在开发一个简单的可执行文件,它应该在 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;
}
4

1 回答 1

0

这些函数是 libc 的一部分,它位于 arm 工具链的目录中。可能您的 arm 工具链配置不正确。检查您的工具链目录并确保 libc.so 确实存在,然后执行nm -g libc.a(使用 nm 的 arm 交叉编译版本,而不是主机版本)。如果这些功能不存在,您可能必须使用适当的选项重新配置/重新编译您的工具链。如果它们在那里,您必须确保您正在尝试链接该库。

于 2015-04-27T18:01:20.833 回答