我发现 Vikram Aggarwal 的一篇文章谈到了将汇编代码链接到 Android 的 NDK,其中甚至有一些示例代码展示了如何将 C++ 代码与汇编连接。(见http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html)
我的问题是我想使用相同的函数,但不是从 JNI 存根类调用它,而是想从我的私有类调用我的 Assembly 函数。
但是在编译时,我得到了错误:
error: 'armFunction' was not declared in this scope
有没有人试过这个或知道如何解决这个问题?
编辑:
生成文件:
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文件中的函数调用:
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();
}