简体   繁体   English

警告:使用了“ void checkGlError(const char *)”,但从未定义

[英]Warning: 'void checkGlError(const char*)' used but never defined

I'm compiling a Shared library using Android NDK r6b. 我正在使用Android NDK r6b编译共享库。 All classes are C++. 所有类都是C ++。

I have the following two classes: 我有以下两节课:

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

When I want to use this function in other C++ files I #include "Utils.hpp" . 当我想在其他C ++文件中使用此功能时,我#include "Utils.hpp" But, in those files I get an error: 但是,在这些文件中,我得到一个错误:

undefined reference to `checkGlError'

Why am I getting this warning? 为什么会收到此警告?

You've made it static . 您已将其static It only lives in that specific translation unit therefore. 因此,它仅存在于该特定翻译单元中。 The solution is to remove the static keyword. 解决方案是删除static关键字。

The warning is telling you that in the header file you "promised" there would be a definition in that translation unity if one was needed, but one has not been provided and it was needed. 警告是告诉您,如果您“需要”头文件中的一个翻译定义,那么如果需要一个,但是没有提供一个,则需要该定义。

static void checkGlError(const char* op);

It is a static function, that means, it has internal linkage, and therefore cannot be called from another translation unit. 它是一个静态函数,也就是说,它具有内部链接,因此不能从另一个翻译单元调用。

Remove the static keyword from it's declaration as well as from it's definition, and it would work fine. 从其声明以及定义中删除static关键字,它将正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM