2011-09-18 101 views
0

我正在使用Android NDK r6b編譯共享庫。所有類都是C++。警告:'void checkGlError(const char *)'被使用但從未定義過

我有以下兩類:

Utils.hpp

#ifdef USE_OPENGL_ES_1_1 
#include <GLES/gl.h> 
#include <GLES/glext.h> 
#else 
#include <GLES2/gl2.h> 
#include <GLES2/gl2ext.h> 
#endif 
#include <android/log.h> 

// Utility for logging: 
#define LOG_TAG "ROTATEACCEL" 
#define LOG(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) 
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) 
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) 

#ifdef __cplusplus 
extern "C" { 
#endif 

static void checkGlError(const char* op); 

#ifdef __cplusplus 
} 
#endif 

Utils.cpp

#include "Utils.hpp" 

#ifdef __cplusplus 
extern "C" { 
#endif 

static void checkGlError(const char* op) { 
    for (GLint error = glGetError(); error; error 
      = glGetError()) { 
     LOGI("after %s() glError (0x%x)\n", op, error); 
    } 
} 

#ifdef __cplusplus 
} 
#endif 

當我想在其他C++文件中使用此功能我#include "Utils.hpp"。但是,在這些文件中出現錯誤:

undefined reference to `checkGlError' 

爲什麼我會收到此警告?

回答

7

你已經做到了static。因此,它只能生活在特定的翻譯單元中。解決方法是刪除static關鍵字。

警告告訴你,在「承諾」的頭文件中,如果需要的話,會在翻譯統一中有一個定義,但是沒有提供一個定義,並且它是需要的。

2
static void checkGlError(const char* op); 

這是一個靜態功能,這意味着,它具有內部連接的,因此不能從另一個翻譯單元調用。

從它的聲明和它的定義中刪除static關鍵字,它會正常工作。

相關問題