我在解决这个问题时遇到了一些麻烦。我在 mac os x 10.9 上使用 cmake 构建了我的 SDL opengl 应用程序,它适用于这个包含头文件
#if defined(__IPHONE__) || defined(__ANDROID__)
#include "SDL_opengles2.h"
#include "SDL_opengles2_gl2.h"
#include "SDL_opengles2_gl2ext.h"
#elif defined(__APPLE__)
#include <OpenGL/gl3.h>
#include <SDL2/SDL_opengl.h>
#endif
尝试使用 ndk-build 构建时出现此错误
jni/src/mandelbrot.c:100:5: warning: implicit declaration of function 'glGenVertexArrays' [-Wimplicit-function-declaration]
glGenVertexArrays(1, &vao);
^
jni/src/mandelbrot.c:106:5: warning: implicit declaration of function 'glBindVertexArray' [-Wimplicit-function-declaration]
glBindVertexArray(vao); //bind vertex array buffer
有人告诉我,在 android openles2 上,它是一个扩展,并且根据 opengl 官方文档
你像这样使用它:glGenVertexArraysOES(...)
除了它是我隐式声明函数 glGenVertexArraysOES 之外,它会产生与上面相同的错误。
完整的 android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -std=c99
LOCAL_MODULE := main
SDL_PATH := ../SDL
SDL_IMG_PATH := ../SDL2_image
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SDL_IMG_PATH)/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SDL_IMG_PATH)/external/jpeg-9/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SDL_IMG_PATH)/external/libpng-1.6.2/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SDL_IMG_PATH)/external/libwebp-0.3.0/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/utils/time_utils/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/utils/resource_utils/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/ren_opengl/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/core_math/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/core_math/commons_math/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/core_math/mat4_scalar/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/core_math/vec3_scalar/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/components/renderable2d/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/core_engine/
# Add your application source files here...
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
utils/time_utils/time_utils.c \
utils/resource_utils/resource_utils.c \
ren_opengl/ren_opengl.c \
core_math/core_math.c \
core_math/mat4_scalar/mat4_scalar.c \
core_math/vec3_scalar/vec3_scalar.c \
components/renderable2d/renderable2d.c \
core_engine/core_engine.c \
mandelbrot.c
LOCAL_SHARED_LIBRARIES := SDL2 SDL2_image
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog
include $(BUILD_SHARED_LIBRARY)
手动删除对 opengl1 的引用对构建结果没有影响。
根据@Michaels 回复编辑 这样做:
PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOES;
glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress ( "glGenVertexArraysOES" );
我收到这些错误消息:
Brother:android-project blubee$ ndk-build
Android NDK: WARNING: APP_PLATFORM android-21 is larger than android:minSdkVersion 10 in ./AndroidManifest.xml
[armeabi] Install : libSDL2.so => libs/armeabi/libSDL2.so
[armeabi] Install : libSDL2_image.so => libs/armeabi/libSDL2_image.so
[armeabi] Compile thumb : main <= mandelbrot.c
jni/src/mandelbrot.c:35:1: warning: data definition has no type or storage class [enabled by default]
glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress ( "glGenVertexArraysOES" );
^
jni/src/mandelbrot.c:35:1: warning: type defaults to 'int' in declaration of 'glGenVertexArraysOES' [enabled by default]
jni/src/mandelbrot.c:35:1: error: conflicting types for 'glGenVertexArraysOES'
jni/src/mandelbrot.c:34:29: note: previous declaration of 'glGenVertexArraysOES' was here
PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOES;
^
jni/src/mandelbrot.c:35:1: warning: implicit declaration of function 'eglGetProcAddress' [-Wimplicit-function-declaration]
glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress ( "glGenVertexArraysOES" );
如果我将名称完全更改为 OES1 之类的名称,那么该错误就会消失,但随后会出现这些错误。
jni/src/mandelbrot.c:54: error: undefined reference to 'eglGetProcAddress'
jni/src/mandelbrot.c:55: error: undefined reference to 'eglGetProcAddress'
jni/src/mandelbrot.c:56: error: undefined reference to 'eglGetProcAddress'
jni/src/mandelbrot.c:57: error: undefined reference to 'eglGetProcAddress'
^
jni/src/mandelbrot.c:35:24: warning: initialization makes integer from pointer without a cast [enabled by default]
glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress ( "glGenVertexArraysOES" );
^
jni/src/mandelbrot.c:35:1: error: initializer element is not constant
glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress ( "glGenVertexArraysOES" );
^
jni/src/mandelbrot.c: In function 'initialized':
jni/src/mandelbrot.c:102:5: warning: implicit declaration of function 'glGenVertexArrays' [-Wimplicit-function-declaration]
glGenVertexArrays(1, &vao);
^
jni/src/mandelbrot.c:108:5: warning: implicit declaration of function 'glBindVertexArray' [-Wimplicit-function-declaration]
glBindVertexArray(vao); //bind vertex array buffer
^
make: *** [obj/local/armeabi/objs/main/mandelbrot.o] Error 1