首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试在Android上使用JNI,但在c程序中获得了未定义的引用。

尝试在Android上使用JNI,但在c程序中获得了未定义的引用。
EN

Stack Overflow用户
提问于 2016-07-11 15:54:14
回答 0查看 248关注 0票数 0

我目前正在尝试与Android一起使用OP-TEE,这是一个开源的信任执行环境,为了让我使用OP-TEE的apis,我必须使用JNI接口。

我当前在Android Studio中的c程序是一个用c编写的hello_world示例,用于操作,我只是想从hello_world.c示例构建一个共享库:

C文件:

代码语言:javascript
复制
#include<jni.h>
#include<string.h>
#include <err.h>
#include "tee_client_api.h"
#include "ta_hello_world.h"
#include <stdio.h>

jstring Java_com_example_jsherman_ndktest_MainActivity_helloWorld(JNIEnv* env,jobject obj){

    TEEC_Result res;
    TEEC_Context ctx;
    TEEC_Session sess;
    TEEC_Operation op;
    TEEC_UUID uuid = TA_HELLO_WORLD_UUID;
    uint32_t err_origin;

    /* Initialize a context connecting us to the TEE */
    res = TEEC_InitializeContext(NULL, &ctx);
    if (res != TEEC_SUCCESS)
        errx(1, "TEEC_InitializeContext failed with code 0x%x", res);

    /*
     * Open a session to the "hello world" TA, the TA will print "hello
     * world!" in the log when the session is created.
     */
    res = TEEC_OpenSession(&ctx, &sess, &uuid,
                   TEEC_LOGIN_PUBLIC, NULL, NULL, &err_origin);
    if (res != TEEC_SUCCESS)
        errx(1, "TEEC_Opensession failed with code 0x%x origin 0x%x",
            res, err_origin);

    /*
     * Execute a function in the TA by invoking it, in this case
     * we're incrementing a number.
     *
     * The value of command ID part and how the parameters are
     * interpreted is part of the interface provided by the TA.
     */

    /*
     * Prepare the argument. Pass a value in the first parameter,
     * the remaining three parameters are unused.
     */
    memset(&op, 0, sizeof(op));
    op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE,
                     TEEC_NONE, TEEC_NONE);
    op.params[0].value.a = 42;

    printf("Invoking TA to increment %d\n", op.params[0].value.a);
    res = TEEC_InvokeCommand(&sess, TA_HELLO_WORLD_CMD_INC_VALUE, &op,
                 &err_origin);
    if (res != TEEC_SUCCESS)
        errx(1, "TEEC_InvokeCommand failed with code 0x%x origin 0x%x",
            res, err_origin);
    printf("TA incremented value to %d\n", op.params[0].value.a);

    /*
     * We're done with the TA, close the session and
     * destroy the context.
     *
     * The TA will print "Goodbye!" in the log when the
     * session is closed.
     */

    TEEC_CloseSession(&sess);

    TEEC_FinalizeContext(&ctx);

    return (*env)->NewStringUTF(env,"Hello world");
}

Android.mk文件:

代码语言:javascript
复制
################################################################################
# Android optee-hello-world makefile                                           #
################################################################################

LOCAL_PATH := $(call my-dir)
CFG_TEEC_PUBLIC_INCLUDE = /home/jsherman/devel/optee/optee_client/public

################################################################################
# Build hello world                                                            #
################################################################################
include $(CLEAR_VARS)


LOCAL_C_INCLUDES := /home/jsherman/devel/optee/optee_hello_world/ta/include \
        $(CFG_TEEC_PUBLIC_INCLUDE) \

$(info $(LOCAL_C_INCLUDES))

LOCAL_SHARED_LIBRARIES := libteec

LOCAL_MODULE := ndktest
LOCAL_SRC_FILES := ndktest.c

include $(BUILD_SHARED_LIBRARY)

由于某种原因,我得到了这个错误:

代码语言:javascript
复制
/home/jsherman/AndroidStudioProjects/NDKTest/jni/ndktest.c:18: undefined reference to `TEEC_InitializeContext'
/home/jsherman/AndroidStudioProjects/NDKTest/jni/ndktest.c:26: undefined reference to `TEEC_OpenSession'
/home/jsherman/AndroidStudioProjects/NDKTest/jni/ndktest.c:50: undefined reference to `TEEC_InvokeCommand'
/home/jsherman/AndroidStudioProjects/NDKTest/jni/ndktest.c:65: undefined reference to `TEEC_CloseSession'
/home/jsherman/AndroidStudioProjects/NDKTest/jni/ndktest.c:67: undefined reference to `TEEC_FinalizeContext'

我有点搞不懂为什么会出现这个错误,因为我在tee_client_api.h所在的LOCAL_C_INCLUDES变量中引用了定义了这些数据结构的正确目录。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38301786

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档