编译大会的android [英] Compiling Assembly for android

查看:194
本文介绍了编译大会的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现由维克拉姆AGGARWAL了一篇文章,谈到联大会code到Android的NDK,其中甚至有一些例如code这显示了如何将C ++ code。与大会交流。
(请参见 http://www.eggwall.com/2011 /09/android-arm-assembly-calling-assembly.html

我的问题是,我想用同样的功能,但不是从JNI存根类调用它,我想从我的私人类叫我装配的功能。

但在编译,我得到的错误:

 错误:'armFunction没有在这个范围内声明

有没有人试过这种或有任何想法如何解决这个问题?

编辑:

的Makefile:

  LOCAL_PATH:= $(叫我-DIR)
包括$(CLEAR_VARS)
LOCAL_MODULE:= QUAKE3#我想ARM,而不是大拇指。
LOCAL_ARM_MODE:=手臂LOCAL_SRC_FILES:= \\
    multiple.s \\
    macros.h \\
    数学/ Vector2.cpp \\
    数学/ Vector3.cpp \\
    数学/ plane.cpp \\
    发动机/ frustum.cpp \\
    发动机/ BoundingVolume.cpp \\
    发动机/ camera.cpp \\
    相机proxy.cpp \\LOCAL_CFLAGS:= -DANDROID_NDK \\
                -DD​​ISABLE_IMPORTGL \\LOCAL_LDLIBS:= -lGLESv1_CM -ldl -llog
#LOCAL_LDLIBS:= -llog -lGLESv2APP_STL:= gnustl_static
APP_CPPFLAGS:= -S -frtti -fexceptions
APP_ABI:= armeabi armeabi,V7A包括$(BUILD_SHARED_LIBRARY)

在CPP文件函数调用:

 无效
Java_surreal_quake3_engine_Camera9_nativeGetDirection(JNIEnv的* ENV,jobject THIZ)
{
    //摄像头*摄像头=(相机*)env-> GetIntField(THIZ,pointerID);    //获取_Z为的Vector3 java对象
    jfieldID vector_fID = env-> GetFieldID(CLS,_Z,Lsurreal /库/数学/的Vector3;);
    jobject vector_obj = env-> GetObjectField(THIZ,vector_fID);    //呼吁_vecEye setter方法
        // JCLASS vectorClass = env->的findClass(超现实主义/库/数学/的Vector3);
    jmethodID vector3_set = env->的GetMethodID(vector3Class设置/ *方法名* /(FFF)V/ *方法签名* /);
    env-> CallVoidMethod(vector_obj,vector3_set,CAMERA-GT&;盖茨()X,CAMERA-方式>盖茨()Y,CAMERA-方式>盖茨()z的);    INT结果= armFunction();
}


解决方案

综观类code,好像你调用函数,但我看不到它的任何声明,因此它是未能识别。因此,你需要调用它(在C ++类)之前有函数原型的声明:

是这样的:

  INT armFunction(无效); //<<宣言无效Java_surreal_quake3_engine_Camera9_nativeGetDirection(JNIEnv的* ENV,jobject THIZ)
{
    //喀嚓 - 管理单元
    INT结果= armFunction(); //<<你的函数调用
}

I found an article by Vikram Aggarwal that talks about linking Assembly code into Android's NDK, which even has some example code which shows how to connect the C++ code with Assembly. ( see http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html )

My problem is that I want to use the same function but instead of calling it from JNI stub class, I want to call my Assembly function from my private class.

But on compilation, I get the error:

error: 'armFunction' was not declared in this scope

Has anyone tried this or have any idea how to resolve this ?

Edit:

Makefile:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := quake3

# I want ARM, not thumb.
LOCAL_ARM_MODE := arm    

LOCAL_SRC_FILES := \
    multiple.s \
    macros.h \
    math/Vector2.cpp\
    math/Vector3.cpp\
    math/plane.cpp\
    engine/frustum.cpp\
    engine/BoundingVolume.cpp\
    engine/camera.cpp\
    camera-proxy.cpp\

LOCAL_CFLAGS := -DANDROID_NDK \
                -DDISABLE_IMPORTGL \

LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
#LOCAL_LDLIBS := -llog -lGLESv2

APP_STL := gnustl_static
APP_CPPFLAGS := -S -frtti -fexceptions
APP_ABI := armeabi armeabi-v7a

include $(BUILD_SHARED_LIBRARY)

Function call in cpp file:

void
Java_surreal_quake3_engine_Camera9_nativeGetDirection(JNIEnv* env, jobject thiz)
{
    //Camera* camera = (Camera*) env->GetIntField(thiz, pointerID);

    // get the _Z as the Vector3 java object
    jfieldID vector_fID = env->GetFieldID(cls, "_Z", "Lsurreal/libs/math/Vector3;");
    jobject vector_obj = env->GetObjectField(thiz, vector_fID);

    // call the setter methods on the _vecEye
        //jclass vectorClass = env->FindClass("surreal/libs/math/Vector3");
    jmethodID vector3_set = env->GetMethodID(vector3Class, "set"/*method-name*/, "(FFF)V" /*method-signature*/);
    env->CallVoidMethod(vector_obj, vector3_set, camera->getZ().x, camera->getZ().y, camera->getZ().z);

    int result = armFunction();
}

解决方案

Looking at the code of the class, it seems like you call the function, but I can't see any declaration of it, so it is not recognized. So you need to have a declaration of the function's prototype before calling it (in the C++ class):

Something like:

int armFunction(void); // << declaration

void Java_surreal_quake3_engine_Camera9_nativeGetDirection(JNIEnv* env, jobject thiz)
{
    // snip - snap
    int result = armFunction(); // << your function call
}

这篇关于编译大会的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆