我得到錯誤LNK2005看似沒有理由,或至少沒有我能夠識別。本質上,使用下面的代碼我可以編譯沒有問題。看似隨機的LNK2005與GLFW3錯誤
test.h
#define GLEW_STATIC
#include <GL\glew.h>
#include <GLFW\glfw3.h>
namespace test
{
//Objects and variables
GLFWwindow* window;
//Function prototypes
bool Initialize();
}
TEST.CPP
#include "test.h"
#include <iostream>
bool test::Initialize()
{
std::cout << "Initializing GLFW: OpenGL version 3.3 \n";
//Initialize GLFW
glfwInit();
//Set window properties (version 3.3, core profile, not resizeable)
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
//Create Window
window = glfwCreateWindow(800, 800, "Learn OpenGL", nullptr, nullptr);
if (window = nullptr)
{
std::cout << "Failed to create GLFW window \n";
glfwTerminate();
return false;
}
return true;
}
int main()
{
test::Initialize();
return 0;
}
然而,編譯時幾乎完全一樣的東西(http://pastebin.com/VpPep9pM),與其他代碼一起,它給人的錯誤:
錯誤LNK2005「struct GLFWwindow * window」(?window @@ 3PAU GLFWwindow @@ A)已在Main.obj OpenGL中定義D:\ Users \ Matthew \ documents \ visual studio 2015 \ Projects \ OpenGL \ OpenGL \ System.obj
錯誤LNK2005「struct GLFWwindow * System :: window」( ?window @ System @@ 3PAUGLFWwindow @@ A)已經在Main.obj OpenGL中定義了D:\ Users \ Matthew \ documents \ visual studio 2015 \ Projects \ OpenGL \ OpenGL \ System.obj
錯誤LNK1169一個或多個乘法定義的符號發現OpenGL的D:\用戶\馬修\文件\視覺工作室2015 \項目\ OpenGL \調試\ OpenGL.exe
所以,我想知道是什麼原因造成的錯誤,我假設它有東西用「背景」來做。