I use CMake to build the project in Visual Studio 2022.
This is the project structure. I picked out the major files
- Sources
- main.cpp
- Forms
- Header
- globalVar.h
- Module
- globalVar.cpp
I declared the global variable in globalVar.h and defined it in globalVar.cpp
// globalVar.h
#ifndef WIND_GLOBAL_VAR
#define WIND_GLOBAL_VAR
#include <QOpenGLFunctions_4_5_Core>
#include <QVector3D>
#include <QVector4D>
extern QOpenGLFunctions_4_5_Core* gl;
extern QVector3D _origin;
extern QVector3D _front;
extern QVector3D _right;
extern QVector3D _up;
#endif
//globalVar.cpp
#include "../Header/globalVar.h"
QOpenGLFunctions_4_5_Core *gl = new QOpenGLFunctions_4_5_Core();
QVector3D _origin(0.0f, 0.0f, 0.0f);
QVector3D _front(0.0f, 0.0f, 1.0f);
QVector3D _right(1.0f, 0.0f, 0.0f);
QVector3D _up(0.0f, 1.0f, 0.0f);
Then in main.cpp I include globalVar.h
But the compiler error, it reported **error C2065: "_up": undeclared identifier **
I don't know if this is my misuse of global variables or something else.