我正在使用 Android NDK r6b 编译共享库。所有类都是 C++。
我有以下两个类:
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'
为什么我会收到此警告?
最佳答案
您已将其设为静态
。因此,它只存在于那个特定的翻译单元中。解决方案是删除 static
关键字。
警告告诉您,在您“ promise ”的头文件中,如果需要的话,该翻译统一体中会有一个定义,但没有提供但需要它。
关于c++ - 警告 : 'void checkGlError(const char*)' used but never defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7460520/