android - 使用 NDK 交叉编译,对 le32toh 和 be32toh 的 undefined reference

标签 android c linker android-ndk

我正在尝试构建一个共享库,最终交叉编译一段使用对 be32tohle32toh 的引用的代码。如果我构建这段代码并从中创建一个可执行文件,我不会收到任何错误:

    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

最佳答案

好吧,显然这些宏在 sys/endian.h 中的 NDK 中有不同的命名:

__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

关于android - 使用 NDK 交叉编译,对 le32toh 和 be32toh 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11702311/

相关文章:

android - 我如何在 Android 中阅读短信?

c - 找到数字乘积为 N 的最小数字 Q

c - 重定向 VxWorks 串行输入

ios - objective-c -Apple Mach-O链接器错误

android - listview 中在 android 中存储图像的问题

java - 删除字符之间的空格

c++ - 链接器如何确定链接到哪个函数?

尝试使用 Code::Blocks 编译第二个模块时出现 C++ 链接器错误

android - android模拟器浏览器中的ERR_NAME_NOT_RESOLVED

复杂指针和结构关系