多个声明的问题gcc
Issues with Multiple Declarations gcc
我正试图在OpenGL项目中使用Nanovg,但多次出现定义错误,如
CMakeFiles\Game.dir/objects.a(Game.cpp.obj):Game.cpp:(.text+0x2e91):"nvgCreateGL3"的多重定义
CMakeFiles\Game.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x2e91):首次在此处定义
游戏.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);
};
游戏.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();`
}
Render.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>
void Game::Render() {
//Definition using Nanovg
}
以下是其他一些可能有用的东西此处提供CMakeLists
此处提供完整控制台输出
我尝试过的
- 在Game.h中放置线
#define NANOVG_GL3_IMPLEMENTATION
- 放置Nanovg包括在Game.h中与
#define ...
进行AND运算 - 尝试更改Game.h和nanovg库与
#includes ...
一起放置的位置(导致未知类型错误)
提前非常感谢您对此问题的帮助
您应该添加以下行:
#define NANOVG_GL3_IMPLEMENTATION
在一个.cpp文件中,因为它看起来像是然后包含了实现。在其他文件中,仅使用标头。
希望这能有所帮助。
我没有看到任何:
#ifndef GAME_H
#define GAME_H
current content of game.h
#endif
所以你可能多次调用game.h。您必须将其包含在代码中,因为可能会多次调用.h文件。
我也遇到了同样的问题。在main.cpp中包含nanovg标头是可行的,但我不能将它们包含在另一个标头中,就像我的Application.h:中这样
#ifndef PROJECT_APPLICATION_H
#define PROJECT_APPLICATION_H
// --------------- INCLUDES
#include "Graphics/Window.h"
#include <nanovg.h>
#define NANOVG_GL3_IMPLEMENTATION
#include <nanovg_gl.h> <..... MOVE this to cpp file!
class Application {
Window window;
NVGcontext* vg;
public:
Application();
~Application();
bool start();
private:
bool setup();
bool clean();
void render() const;
};
#endif //PROJECT_APPLICATION_H
然而,将nanovg_gl include移动到Application.cpp是可行的。
// ---------------- INCLUDES
#include "Application.h"
// ----------------
#include <nanovg_gl.h> <---- HERE
Application::Application()
:window("Window", 1920 / 2, 1080 / 2)
{
setup();
}
Application::~Application() {
}
/**
* Handling rendering here...
*/
void Application::render() const {
nvgBeginFrame(vg, 1920 / 2, 1080 / 2, 1920 / 1080);
nvgBeginPath(vg);
nvgRect(vg, 100,100, 120,30);
nvgCircle(vg, 120,120, 5);
nvgPathWinding(vg, NVG_HOLE);
nvgFillColor(vg, nvgRGBA(255,192,0,255));
nvgFill(vg);
nvgEndFrame(vg);
}
...
相关文章:
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- GCC 问题与 static_cast<std::u16string>
- 具有sleep_for和sleep_until功能的 gcc 可能存在的问题
- 调试模板时出现问题.专门针对 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 错误构建失败:模板参数 1
- 使用具有默认参数的函数模板进行 decltype 会使结果混乱(一个有趣的问题或 gcc 的错误)
- 没有'str'成员在 GCC 和 Clang 'std::basic_ostream<char>',但 MSVC 没有问题
- macos GCC 工具链编译简单 hello 世界的问题
- 使用不同版本的 gcc 和 g++ 进行编译时出现问题
- C++ GCC 的部分模板专用化问题
- GCC 与 Clang 公共库问题
- 与lambda一起使用虚拟继承在初始化列表中捕获此问题的GCC错误
- 将GCC版本升级到发行版附带的版本以外的版本是否有任何问题
- 在 gcc 中使用 fsanitize 开关的 Boost 出现问题
- 在 Windows 10 中运行 gcc 插件的问题
- Linux 中 gcc 4.3 版本的编译问题
- 当编译指向可能抛出的函数的非throwing时,gcc有什么问题吗
- Linux gcc 编译问题
- GCC:函数包装器模板问题
- 多个声明的问题gcc
- 多重继承的菱形问题:Gcc / Clang错误,但Visual Studio没有错误