在终端中使用ndk-build编译以下C代码时(我正在运行Ubuntu): #include jni.h#include GLES/gl.h#include GLES/glext.h#include "org_opengldrawinjni_DrawinJNI.h"JNIEXPORT void JNICALL Java_org_opengldrawinjni_DrawinJNI_Draw (JNIEn
#include <jni.h> #include <GLES/gl.h> #include <GLES/glext.h> #include "org_opengldrawinjni_DrawinJNI.h" JNIEXPORT void JNICALL Java_org_opengldrawinjni_DrawinJNI_Draw (JNIEnv *envptr, jobject jobj) { GLfloat vertices[] = { 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 }; GLubyte indices[] = { 0, 1, 2 }; glVertexPointer(3, GL_FLOAT, 0, vertices); glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, indices); }
使用此Android.mk文件:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := OpenGLJNI LOCAL_SRC_FILES := org_opengldrawinjni_DrawinJNI.c LOCAL_LDLIBS := -llog -lGLESv1_CM.so include $(BUILD_SHARED_LIBRARY)
我得到一个错误,未定义的glVertexPointer引用.我想知道为什么,因为我相信我正确地包含了标题并链接了Android.mk中的库
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/OpenGLDrawinginJNI/obj/local/armeabi/objs/OpenGLJNI/org_opengldrawinjni_DrawinJNI.o: In function `Java_org_opengldrawinjni_DrawinJNI_Draw': /home/thomas/Documents/LinuxProgramming/EclipseWorkspace/OpenGLDrawinginJNI/jni/org_opengldrawinjni_DrawinJNI.c:33: undefined reference to `glVertexPointer' collect2: ld returned 1 exit status make: *** [/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/OpenGLDrawinginJNI/obj/local/armeabi/libOpenGLJNI.so] Error 1
谢谢!
我想不出有什么不对,但是当我查看我的make文件时,有一点不同.由于我对编译器不熟悉,我不知道它是否相关:
LOCAL_LDLIBS:= – lGLESv1_CM -ldl -llog
Dynamic Linker Library:
is available and can be used
to use the dlopen()/dlsym()/dlclose()
functions provided by the Android
dynamic linker. You will need to link
against /system/lib/libdl.so with:LOCAL_LDLIBS := -ldl
希望能帮助到你