c++ - 警告 : 'void checkGlError(const char*)' used but never defined

标签 c++ compiler-errors

我正在使用 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/

相关文章:

c# - 为什么 C# 不能正确绑定(bind)泛型覆盖方法?

c++ - 奇怪的重新定义的符号

c++ - Opencv 异常 fillconvexppoly

c# - 制作 C++/MFC 应用程序以从其他应用程序中提取 AssemblyInfo?

qt - 为 Visual Studio Community 2015 构建 Qt 5.6.0 时出错

perl - 无法编译我的 perl 脚本。让一切正常工作的最简单方法是什么?

c++ - 从头文件调用CPP函数

c++ - strtok_s安全调试警告解决

c++ - 无法使用 XMLDocument - "incomplete type is not allowed"

c++ - 为什么程序在堆栈展开后无法到达正确的返回指令?