2012-07-28 270 views
3

我試圖構建一個共享庫,最終的交叉編譯一段代碼,用來引用be32tohle32toh。如果我建立這一段代碼,並創建一個可執行文件出來吧,我沒有得到任何錯誤:交叉編譯使用NDK,未定義的引用le32toh和be32toh

include $(CLEAR_VARS) 
    LOCAL_SRC_FILES:= ubertooth.c ubertooth_helper.c 
    LOCAL_MODULE := ubertooth 
    LOCAL_C_INCLUDES += jni/libusb jni/libbtbb 
    LOCAL_SHARED_LIBRARIES := libc libusb libbtbb 
    LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog 
    include $(BUILD_EXECUTABLE) 

這編譯成功:

Compile thumb : ubertooth <= ubertooth.c 
    Compile thumb : ubertooth <= ubertooth_helper.c 
    Executable  : ubertooth 
    Install  : ubertooth => libs/armeabi/ubertooth 

然而,當我試圖把它做成一個共享庫僅通過改變在Android.mk一行:

include $(CLEAR_VARS) 
    ... 
    include $(BUILD_SHARED_LIBRARY) 

我現在得到以下錯誤:

Compile thumb : ubertooth <= ubertooth.c 
    Compile thumb : ubertooth <= ubertooth_helper.c 
    SharedLibrary : libubertooth.so 
    ./obj/local/armeabi/objs-debug/ubertooth/ubertooth.o: In function `stream_rx_file': 
    ubertooth.c:224: undefined reference to `be32toh' 
    ./obj/local/armeabi/objs-debug/ubertooth/ubertooth.o: In function `cb_lap': 
    ubertooth.c:281: undefined reference to `le32toh' 
    ./obj/local/armeabi/objs-debug/ubertooth/ubertooth.o: In function `cb_hop': 
    ubertooth.c:417: undefined reference to `le32toh' 
    ./obj/local/armeabi/objs-debug/ubertooth/ubertooth.o: In function `cb_btle': 
    ubertooth.c:506: undefined reference to `le32toh' 
    collect2: ld returned 1 exit status 

我不明白爲什麼我會在構建共享庫時得到此鏈接錯誤,而不是在構建可執行文件時。而且,如果我想構建共享庫,如何正確鏈接到我缺少的東西?

Here is ubertooth.c

+0

什麼當你使用「ndk-build V = 1」構建一個可執行文件和共享庫時,它的區別是什麼?有不同的D標誌嗎? – wojciii 2012-07-28 17:09:06

回答

3

很好,顯然這些宏被命名爲不同的NDK在sys/endian.h發現:

__uint64_t htobe64(__uint64_t); 
__uint32_t htobe32(__uint32_t); 
__uint16_t htobe16(__uint16_t); 
__uint64_t betoh64(__uint64_t); 
__uint32_t betoh32(__uint32_t); 
__uint16_t betoh16(__uint16_t); 

__uint64_t htole64(__uint64_t); 
__uint32_t htole32(__uint32_t); 
__uint16_t htole16(__uint16_t); 
__uint64_t letoh64(__uint64_t); 
__uint32_t letoh32(__uint32_t); 
__uint16_t letoh16(__uint16_t); 

所以,我用letoh32betoh32