3
我試圖構建一個共享庫,最終的交叉編譯一段代碼,用來引用be32toh和le32toh。如果我建立這一段代碼,並創建一個可執行文件出來吧,我沒有得到任何錯誤:交叉編譯使用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
我不明白爲什麼我會在構建共享庫時得到此鏈接錯誤,而不是在構建可執行文件時。而且,如果我想構建共享庫,如何正確鏈接到我缺少的東西?
什麼當你使用「ndk-build V = 1」構建一個可執行文件和共享庫時,它的區別是什麼?有不同的D標誌嗎? – wojciii 2012-07-28 17:09:06