标签:android-ndk linker c-3 android
我试图建立一个共享库,最终交叉编译一段使用对be32toh和le32toh的引用的代码.如果我构建这段代码并从中创建可执行文件,则不会出错:
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
我不明白为什么在构建共享库时会出现此链接错误,而在构建可执行文件时却不会.而且,如果我想构建共享库,如何正确链接到我所缺少的东西?
解决方法:
好吧,显然这些宏在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);
所以,我用letoh32和betoh32
标签:android-ndk,linker,c-3,android 来源: https://codeday.me/bug/20191201/2077442.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。