2015-04-27 26 views
1

我正在開發一個應該Android系統啓動時運行一個簡單的可執行文件。它使用一個小型的tinydir.h庫來瀏覽特定目錄中的文件。即使它(使用gcc在OS X),當我嘗試用Android系統本身(ARM)來構建它,我得到以下輸出編譯就好了用於x86和x86_64:C源代碼不會編譯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

你能提供一個完整的可再現的例子嗎?爲什麼你明確提供'-lc'? – fuz

+0

'C可執行文件不能編譯ARM體系結構。這是無稽之談。一個不編譯可執行文件。你需要:'C源代碼不能編譯ARM架構'? – greenapps

+0

@FUZxxl我已編輯帖子以包含示例代碼。這不是我使用的整個文件,但應該足夠了。我添加了很多標誌,試圖使代碼正常工作。我意識到他們中的大多數是不必要的。 –

回答

0

這些功能的libc的一部分,它位於你的手臂工具鏈的目錄。可能你的手臂工具鏈配置不正確。檢查你的工具鏈目錄,並確保libc.so確實存在,並且做一個nm -g libc.a(使用納米的手臂交叉編譯版本,而不是主機版本)。如果這些功能不存在,您可能需要重新配置/重新編譯您的工具鏈,並使用適當的選項。如果他們在那裏,你必須確保你試圖鏈接到該庫。

+0

的海報試圖將代碼構建爲Android系統資源的整體構建的一部分 - 這個過程包括獲取並使用正確配置的工具鏈來交叉編譯目標。如果安裝出現問題,在建立庫存代碼時可能會失敗,然後再進行自定義。此外,代碼應該根據Bionic libc的本地編譯版本進行構建,而不是像NDK那樣裝載的代碼。 –