android中 JIN编译报错
16lz
2021-12-04
android中 JIN编译报错
编译报错: fatal error: string: No such file or directory
在开发一个测试用例时,需要用到一个JIN去调用底层借口,JIN文件为:otp_rw.cpp,然后相关makefile如下:
include $(CLEAR_VARS)# This is the target being built.LOCAL_MODULE:= libnative-libLOCAL_MODULE_TAGS := optional# All of the source files that we will compile.LOCAL_SRC_FILES:= \ native-lib.cpp\# All of the shard libraries we link against.LOCAL_SHARED_LIBRARIES := liblog# Also need the JNI headers.LOCAL_C_INCLUDES += \ $(JNI_H_INCLUDE)include $(BUILD_SHARED_LIBRARY)
编译时,出现错误。
- fatal error: string: No such file or directory
target thumb C++: libOTP_rw_test <= development/apps/project/jni/otp_rw.cppdevelopment/apps/project/jni/otp_rw.cpp:14:18: fatal error: string: No such file or directory #include ^compilation terminated.build/core/binary.mk:620: recipe for target 'out/target/product/morpho/obj/SHARED_LIBRARIES/libOTP_rw_test_intermediates/otp_rw.o' failedmake: *** [out/target/product/morpho/obj/SHARED_LIBRARIES/libOTP_rw_test_intermediates/otp_rw.o] Error 1make: Leaving directory '/home/administrator/projects/morpho_iris'
从log上来看是不能识别string,推测是缺少相应的依赖。
2. error: cast to ‘unsigned char *’ from smaller integer type ‘int’
development/apps/project/jni/otp_rw.cpp:356:25: error: cast to 'unsigned char *' from smaller integer type 'int' [-Werror,-Wint-to-pointer-cast] uint8_t *database = (uint8_t *)GetBuffer(&size);
从log上来看是将int型转换成unsigned char *
指针类型,而int太小了。后面将int强制转换成long后再cast to 'unsigned char *
好像可以解决这个问题。
最后通过添加STL支持,问题一 和问题二 都可以解决具体修改如下:
include $(CLEAR_VARS)# This is the target being built.LOCAL_MODULE:= libnative-libLOCAL_MODULE_TAGS := optionalLOCAL_LDFLAGS += -ldlLOCAL_C_INCLUDES += \ bionic \ bionic/libstdc++/include \ external/stlport/stlport# All of the source files that we will compile.LOCAL_SRC_FILES:= \ native-lib.cpp\# All of the shard libraries we link against.LOCAL_SHARED_LIBRARIES := liblogAPP_STL := stlport_static# Also need the JNI headers.LOCAL_C_INCLUDES += \ $(JNI_H_INCLUDE)include $(BUILD_SHARED_LIBRARY)
更多相关文章
- mybatisplus的坑 insert标签insert into select无参数问题的解决
- Android(安卓)Studio 使用中遇到的问题和解决方案
- Android(安卓)Sdk Manager更新
- ndk 编译android内核模块无法加载 解决方法
- Android(安卓)编译手册
- [Android开发常见问题-21] Android(安卓)近百个项目的源代码
- Android——eclipse共享library以及导出jar包
- Android(安卓)常见知识整理(1)
- Ubuntu 14.10+NDK+ffmpeg编译+Android