2011-09-18 2 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++ 파일에이 기능을 사용하려면 I #include "Utils.hpp".

undefined reference to `checkGlError' 

이유는이 경고를 받고 있습니다 :하지만, 해당 파일에 오류가 발생합니다?

답변

7

당신은 그것을 static으로 만들었습니다. 그러므로 특정 번역 단위에만 존재합니다. 해결 방법은 static 키워드를 제거하는 것입니다.

경고 메시지는 헤더 파일에서 "약속 됨"이라는 메시지가 나타납니다. 필요한 경우 번역 통합 단위에 정의가 있지만 하나는 제공되지 않았고 필요합니다.

2
static void checkGlError(const char* op); 

그것은 정적 함수는 내부 결합을 갖고, 그 의미이므로 다른 번역 부로부터 호출 될 수 없다.

그것의 선언에서뿐만 아니라 선언에서 static 키워드를 제거하십시오, 잘 일할 것입니다.

관련 문제