NDK的OpenGL未定义参考glVertexPointer [英] NDK OpenGL undefined reference to glVertexPointer

查看:492
本文介绍了NDK的OpenGL未定义参考glVertexPointer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编译下面的C code。与NDK的构建在终端(我运行Ubuntu):

 的#include< jni.h>#包括LT&; GLES / gl.h>
#包括LT&; GLES / glext.h>#包括org_opengldrawinjni_DrawinJNI.h
JNIEXPORT无效JNICALL Java_org_opengldrawinjni_DrawinJNI_Draw
  (JNIEnv的* envptr,jobject jobj)
{
 GLfloat顶点[] =
  {1.0,0.0,0.0,
    1.0,1.0,0.0,
    0.0,0.0,0.0
  };
 GLubyte指数[] = {0,1,2};
 glVertexPointer(3,GL_FLOAT,0,顶点);
 glDrawElements(GL_TRIANGLES,3,GL_UNSIGNED_BYTE,索引);
}

本Android.mk文件:

  LOCAL_PATH:= $(叫我-DIR)   包括$(CLEAR_VARS)   LOCAL_MODULE:= OpenGLJNI
   LOCAL_SRC_FILES:= org_opengldrawinjni_DrawinJNI.c
   LOCAL_LDLIBS:= -llog -lGLESv1_CM.so   包括$(BUILD_SHARED_LIBRARY)

我得到一个错误,未定义的引用glVertexPointer。我不知道为什么,因为我相信我适当地包括报头,并在Android.mk拉上库

<$p$p><$c$c>/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/OpenGLDrawinginJNI/obj/local/armeabi/objs/OpenGLJNI/org_opengldrawinjni_DrawinJNI.o:在功能上`Java_org_opengldrawinjni_DrawinJNI_Draw:
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/OpenGLDrawinginJNI/jni/org_opengldrawinjni_DrawinJNI.c:33:未定义的引用`glVertexPointer
collect2:劳工处返回1退出状态
使:*** [/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/OpenGLDrawinginJNI/obj/local/armeabi/libOpenGLJNI.so]错误1

谢谢!


解决方案

我想不出什么错,但是当我检查了我的make文件有一个区别。
因为我不擅长与编译器,我不知道这是否是相关的:

LOCAL_LDLIBS:= -lGLESv1_CM -ldl -llog


  

动态链接库:


  
  

是可用的,并可用于
  使用的dlopen()/ dlsym进行()/ dlclose()
  通过在Android提供的功能
  动态连接器。您将需要链接
  针对与/system/lib/libdl.so:


  
  

LOCAL_LDLIBS:= -ldl


希望它能帮助

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!

解决方案

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

这篇关于NDK的OpenGL未定义参考glVertexPointer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆