我正在使用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'
为什么我会收到此警告?
答案 0 :(得分:7)
你已成功static
。因此,它只存在于特定的翻译单元中。解决方案是删除static
关键字。
警告告诉您,在“承诺”的头文件中,如果需要一个,那么在该翻译统一中将有一个定义,但是没有提供一个并且需要它。
答案 1 :(得分:2)
static void checkGlError(const char* op);
这是一个静态函数,这意味着它具有内部链接,因此无法从另一个翻译单元调用。
从它的声明中删除static
关键字以及它的定义,它会正常工作。