每當我嘗試編譯並運行我的C++ SDL/Glew遊戲時,出現鏈接器錯誤:LNK2019。我已經在MSDN中研究過它,並且說它是C++文件中的C代碼,不包含在extern'C'{...}中。C++ Glew LNK2019錯誤
我在Windows 8.1上使用Visual Studio 2015社區和最新版本的Glew。
這裏是我不斷收到錯誤:
LNK2019: unresolved external symbol [email protected] referenced in function "private void _thiscall MainGame::draw(void)" ([email protected]@2AAeXXZ)
LNK2019: unresolved external symbol [email protected] referenced in function "private: void _thiscall MainGame::initSystems(void)" ([email protected]@@AAEXXZ)
LNK2019: unresolved external symbol [email protected] referenced in function "private void _thiscall MainGame::draw(void)" ([email protected]@@AAEXXZ
MainGame.cpp:
#include "MainGame.h"
void fatalError(std::string errorString) {
std::cout << "FATAL ERROR:" << errorString << std::endl;
std::cout << "Enter any key to quit...";
int tmp;
std::cin >> tmp;
SDL_Quit();
exit(1);
}
MainGame::MainGame() {
window = nullptr;
width = 960;
height = 540;
gameState = GameState::PLAY;
}
MainGame::~MainGame() {
}
void MainGame::run() {
initSystems();
gameLoop();
}
void MainGame::initSystems() {
SDL_Init(SDL_INIT_EVERYTHING);
window = SDL_CreateWindow("Acorn", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
if (window == nullptr) {
fatalError("Failed to Initialize the Window");
}
SDL_GLContext glContext = SDL_GL_CreateContext(window);
if (glContext == nullptr) {
fatalError("Failed to Initialize OpenGL");
}
GLenum error = glewInit();
if (error != GLEW_OK) {
fatalError("Failed to Initialize Glew");
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
void MainGame::processInput() {
SDL_Event sdlevent;
while (SDL_PollEvent(&sdlevent)) {
switch (sdlevent.type) {
case SDL_QUIT:
gameState = GameState::QUIT;
break;
}
}
}
void MainGame::draw() {
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapWindow(window);
}
void MainGame::gameLoop() {
while (gameState != GameState::QUIT) {
draw();
processInput();
}
}
MainGame.h:
#pragma once
#include <GL/glew.h>
#include <SDL/SDL.h>
#include <iostream>
#include <string>
enum class GameState {
PLAY,
QUIT
};
class MainGame {
public:
MainGame();
~MainGame();
void run();
private:
GameState gameState;
int width, height;
SDL_Window* window;
void initSystems();
void gameLoop();
void processInput();
void draw();
};
可能重複[什麼是未定義的引用/無法解析的外部符號錯誤,以及如何解決它?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-外部符號錯誤和如何-DO-修復) – genpfault