我发现Vikram Aggarwal的一篇文章讨论了将汇编代码链接到Android的NDK,甚至还有一些示例代码,展示了如何将C ++代码与Assembly连接起来。 (见http://www.eggwall.com/2011/09/android-arm-assembly-calling-assembly.html)
我的问题是我想使用相同的函数,但不是从JNI存根类调用它,我想从我的私有类中调用我的汇编函数。
但是在编译时,我收到错误:
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();
}
答案 0 :(得分:1)
查看类的代码,看起来你调用了这个函数,但我看不到它的任何声明,因此无法识别。所以你需要在调用之前声明函数的原型(在C ++类中):
类似的东西:
int armFunction(void); // << declaration
void Java_surreal_quake3_engine_Camera9_nativeGetDirection(JNIEnv* env, jobject thiz)
{
// snip - snap
int result = armFunction(); // << your function call
}