我试图在我的OpenGL项目中使用Nanovg,并且遇到重复的多个定义错误,例如
Game.h
class Game {
public:
void Run();
Game(std::string Title, ScreenMode ScreenMode, int Width, int MSAASamples, bool VSync);
private:
GLFWwindow* Window;
NVGcontext* VGContext;
std::string Title;
ScreenMode Mode;
int Width, Height;
int WWidth, WHeight;
int FBWidth, FBHeight;
int MSAASamples;
bool VSync;
bool Exit;
float PixRatio;
void Process();
void Render();
void KeyCallback(GLFWwindow* Window, int Key, int Scancode, int Action, int Mode);
void SaveScreenShot(const std::string* Path);
};
Game.cpp
//various #includes .. (STL GlaD, GLFW)
#ifndef NANOVG_INCLUDED
#define NANOVG_INCLUDED
#include <nanovg.h>
#define NANOVG_GL3_IMPLEMENTATION
#include <nanovg_gl.h>
#endif
// More #includes ...
#include <Game.h>
Game::Game(std::string Title, ScreenMode ScreenMode, int Width, int MSAASamples, bool VSync)
{
// constructor here
}
void Game::Run(){
// Initialise openGl and NanoVG, then into main game loop calling `Render();`
}
渲染器
//various #includes .. (STL GlaD, GLFW)
#ifndef NANOVG_INCLUDED
#define NANOVG_INCLUDED
#include <nanovg.h>
#define NANOVG_GL3_IMPLEMENTATION
#include <nanovg_gl.h>
#endif
// More #includes ...
#include <Game.h>
void Game::Render() {
//Definition using Nanovg
}
这是一些其他有用的东西
CMakeLists Available Here
Full Console output Available Here
我尝试过的
#define NANOVG_GL3_IMPLEMENTATION
行放在Game.h中#define ...
#includes ...
一起放置(导致未知的类型错误)预先非常感谢您提供有关此问题的帮助
最佳答案
您应该添加以下行:
#define NANOVG_GL3_IMPLEMENTATION
仅在一个.cpp文件中,因为看起来它包含了当时的实现。在其他文件中,仅使用 header 。
希望这可以帮助。
关于c++ - gcc多个声明的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36337467/