android中 JIN编译报错

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-lib
LOCAL_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)

编译时,出现错误。

  1. fatal error: string: No such file or directory
target thumb C++: libOTP_rw_test <= development/apps/project/jni/otp_rw.cpp
development/apps/project/jni/otp_rw.cpp:14:18: fatal error: string: No such file or directory
 #include <string>
                  ^
compilation terminated.
build/core/binary.mk:620: recipe for target 'out/target/product/morpho/obj/SHARED_LIBRARIES/libOTP_rw_test_intermediates/otp_rw.o' failed
make: *** [out/target/product/morpho/obj/SHARED_LIBRARIES/libOTP_rw_test_intermediates/otp_rw.o] Error 1
make: 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-lib
LOCAL_MODULE_TAGS := optional
LOCAL_LDFLAGS += -ldl
LOCAL_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 := liblog
APP_STL := stlport_static
# Also need the JNI headers.
LOCAL_C_INCLUDES += \
 $(JNI_H_INCLUDE)
include $(BUILD_SHARED_LIBRARY)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值