每当我尝试编译并运行我的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