NDK OpenGL 未定义对 glVertexPointer 的引用

发布于 2024-10-03 10:33:17 字数 1438 浏览 2 评论 0原文

在终端中使用 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
  (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

谢谢!

When compiling the following C code with ndk-build in Terminal (I'm running 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
  (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);
}

with this Android.mk file:

   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)

I get an error, undefined reference to glVertexPointer. I'm wondering why because I believe I properly included the headers and linked up the libraries in the 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

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转角预定愛 2024-10-10 10:33:17

我想不出有什么问题,但是当我检查我的 make 文件时,发现有一个区别。
由于我不擅长编译器,我不知道它是否相关:

LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog

动态链接器库:

可用并且可以使用
使用 dlopen()/dlsym()/dlclose()
Android提供的功能
动态链接器。您需要链接
针对 /system/lib/libdl.so :

LOCAL_LDLIBS := -ldl

希望有帮助

I can't think of anything wrong but when I checked my make file there is one difference.
Since I'm not good with compilers I don't know if it is relevant:

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

Hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文