为android编译程序集 [英] Compiling Assembly for android
问题描述
我找到了 Vikram Aggarwal 的一篇文章,其中谈到了将汇编代码链接到 Android 的 NDK 中,其中甚至还有一些示例代码,展示了如何将 C++ 代码与汇编连接起来.(见 http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html )
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 )
我的问题是我想使用相同的函数,但不是从 JNI 存根类调用它,而是想从我的私有类调用我的程序集函数.
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 ?
生成文件:
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)
cpp 文件中的函数调用:
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();
}
推荐答案
看类的代码,好像是调用了函数,但是我看不到它的任何声明,因此无法识别.所以你需要在调用之前声明函数的原型(在 C++ 类中):
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):
类似于:
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屋!