Whenever I try to compile and run my C++ SDL/Glew game, I get the linker error: LNK2019. I've looked into it in the MSDN and that says that it's C code in a C++ file not wrapped in an extern 'C' { ... }.
I'm using Visual Studio 2015 Community and the latest version of Glew, on Windows 8.1.
Here is the Error I keep getting:
LNK2019: unresolved external symbol _imp_glClear@4 referenced in function "private void _thiscall MainGame::draw(void)" (?draw@MainGame@2AAeXXZ)
LNK2019: unresolved external symbol _imp_glClearColor@16 referenced in function "private: void _thiscall MainGame::initSystems(void)" (?initSystems@MainGame@@AAEXXZ)
LNK2019: unresolved external symbol _imp_glClearDepth@8 referenced in function "private void _thiscall MainGame::draw(void)" (?draw@MainGame@@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();
};