Already Defined / Multiple Object Definitions / Visual Studio - c++

I'm following along with a video tut on SDL. When I do exactly as he has done, by putting an SDL_Texture* in the Game.h and use the object in Game.cpp, I get an error about multiple definitions. Yet, the video creator has no error of such. I can, however, copy and paste the SDL_Texture* to the .cpp and it work just fine.
Why is it that the same code will work on one, but not another machine, in Visual Studio
Game.cpp
#include "Game.h"
Game::Game()
{
}
Game::~Game()
{
}
void Game::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
{
int flags = 0;
if (fullscreen)
{
flags = SDL_WINDOW_FULLSCREEN;
}
if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
std::cout << "Successfully Initialized Subsystem . . . " << std::endl;
window = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
if (window)
{
std::cout << "Successfully Created Window . . . " << std::endl;
}
else
{
std::cout << "Something went wrong. Error: " << SDL_GetError() << std::endl;
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer)
{
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
std::cout << "Successfully Created Renderer . . . " << std::endl;
}
else
{
std::cout << "Something went wrong. Error: " << SDL_GetError() << std::endl;
}
is_running = true;
}
else
{
is_running = false;
}
SDL_Surface* surf_temp = IMG_Load("assets/player.png");
tex_player = SDL_CreateTextureFromSurface(renderer, surf_temp);
SDL_FreeSurface(surf_temp);
}
void Game::event_handle()
{
SDL_Event event;
SDL_PollEvent(&event);
switch (event.type)
{
case SDL_QUIT:
is_running = false;
}
}
void Game::update()
{
cnt++;
std::cout << cnt << std::endl;
}
void Game::render()
{
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, tex_player, NULL, NULL);
SDL_RenderPresent(renderer);
}
void Game::clean()
{
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_Quit();
std::cout << "Game cleaned . . . " << std::endl;
}
Game.h
#include "SDL.h"
#include "SDL_image.h"
#include <iostream>
#include <stdio.h>
#include <string>
SDL_Texture* tex_player;
class Game
{
public:
Game();
~Game();
void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
void event_handle();
void update();
void render();
void clean();
bool running() { return is_running; }
private:
int cnt;
bool is_running;
SDL_Window *window;
SDL_Renderer *renderer;
};
main.cpp
#include "Game.h"
Game *game = nullptr;
int main(int argc, char *argv[])
{
game = new Game();
game->init("Yeah", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, false);
while (game->running())
{
game->event_handle();
game->update();
game->render();
}
game->clean();
return 0;
}
Error:
1>------ Build started: Project: SDL_Template, Configuration: Debug Win32 ------
1>main.cpp
1>LINK : C:\Users\Onion\documents\visual studio 2017\Projects\SDL_Template\Debug\SDL_Template.exe not found or not built by the last incremental link; performing full link
1>main.obj : error LNK2005: "struct SDL_Texture * tex_player" (?tex_player##3PAUSDL_Texture##A) already defined in Game.obj
1>C:\Users\Onion\documents\visual studio 2017\Projects\SDL_Template\Debug\SDL_Template.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Done building project "SDL_Template.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Think of #include as "please copy-paste the content of this file here."
Since you #includeGame.h in both main.cpp and Game.cpp, the line SDL_Texture* tex_player; which is a global variable definition (as opposed to declaration) appears in both files, which confuses the linker.
The immediate fix is to declare the variable in game.h:
extern SDL_Texture* tex_player;
and define it in game.cpp
SDL_Texture* tex_player;
The better fix would be to make tex_player a member variable of Game (or some other class).

Related

I get an "unresolved external symbol" error, but it can access them in visual studio LNK2019/LNK 1120

So I'm just trying to set up a game loop and window, but it won't even start with a blank screen. When I run it, it gives me an error every time I try to use any function from SDL. I have the .dll in the same folder as the project files and in the Debug folder. I'm pretty sure I have them linked in the project properties, too, but I don't know. When I'm in visual studio, I can hover over the functions and it has the declarations of them (I think)
SDL2\include is in VC++ Directories -> Include Directories
SDL2\lib\x64 is in VC++ Directories -> Library Directories
SDL2\include is also in C/C++ -> General -> Additional Include Directories
SDL2\lib\x64 is also in Linker -> General -> Additional Library Directories
SDL.lib and SDLmain.lib are both in Linker -> Input -> Additional Dependencies
edit: forgot to show project properties
This is Game.hpp
#include "SDL.h"
#include <iostream>
class Game
{
public:
Game();
~Game();
void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
void handleEvents();
void update();
void render();
void clean();
bool running() { return isRunning; }
private:
int cnt = 0;
bool isRunning;
SDL_Window *window;
SDL_Renderer *renderer;
};
This is Game.cpp
#include "Game.hpp"
Game::Game()
{}
Game::~Game()
{}
void Game::init(const char *title, int xpos, int ypos, int width, int height, bool fullscreen)
{
int flags = 0;
if (fullscreen)
{
flags = SDL_WINDOW_FULLSCREEN;
}
if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
std::cout << "Subsystems initialized" << std::endl;
window = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
if (window)
{
std::cout << "Window created" << std::endl;
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer)
{
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
std::cout << "Renderer created" << std::endl;
}
isRunning = true;
} else {
isRunning = false;
}
}
void Game::handleEvents()
{
SDL_Event event;
SDL_PollEvent(&event);
switch (event.type)
{
case SDL_QUIT:
isRunning = false;
break;
default:
break;
}
}
void Game::update()
{
cnt++;
std::cout << cnt << std::endl;
}
void Game::render()
{
SDL_RenderClear(renderer);
//add stuff to render
SDL_RenderPresent(renderer);
}
void Game::clean()
{
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_Quit();
std::cout << "Game cleaned" << std::endl;
}
And this is main.cpp
#include "Game.hpp"
Game *game = nullptr;
int main(int argc, char *argv[]) {
game = new Game();
game->init("Maxgame", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, false);
while (game->running()) {
game->handleEvents();
game->update();
game->render();
}
game->clean();
return 0;
}
And these are the
errors
I'm getting.
You could set Linker -> Advanced -> Target Machine -> MachineX64 in Properties.

LNK1120 error and LNK2019 error inside include line game dev?

I'm currently using this tutorial: https://www.youtube.com/watch?v=44tO977slsU&list=PLhfAbcv9cehhkG7ZQK0nfIGJC_C-wSLrx&index=3
But I've been getting this error on the first line that I don't know how to address as a beginner.
It says it's unresolved externals
I've been trying to look at some of the windows config advice, but I don't know how to apply it to this tutorial.
here's the code:
#include "Header.hpp"
Game::Game(){}
Game::~Game(){}
void Game::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
{
int flags = 0;
if (fullscreen) { flags = SDL_WINDOW_FULLSCREEN; }
if (SDL_Init(SDL_INIT_EVERYTHING) == 0) {
std::cout << "Subsystems initialized" << std::endl;
window = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
if (window) { std::cout << "Windows created" << std::endl; }
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer) {
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
std::cout << "renderer created" << std::endl;
}
isRunning == true; } else { isRunning == false; }
}
void Game::handleEvents() {
SDL_Event event;
SDL_PollEvent(&event);
switch (event.type) {
case SDL_QUIT:
isRunning = false;
break;
default:
break;
}
}
void Game::update() { count++; std::cout << count << std::endl; }
void Game::render() {
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
void Game::clean() {
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_Quit();
std::cout << "Game cleaned" << std::endl;
}
this is is the header file, if it'll help:
#ifndef Header_hpp
#define Header_hpp
#include <iostream>
#include "SDL.h"
class Game {
public:
Game();
~Game();
void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
void handleEvents();
void update();
void render();
void clean();
bool running(){ return isRunning; }
private:
int count = 0;
bool isRunning;
SDL_Window *window;
SDL_Renderer *renderer;
};
#endif / * Header_hpp */
I'm genuinely clueless on what could be causing this so I guess I'll include the main.cpp as well if something can be found there:
#include "Header.hpp"
Game* game = nullptr;
int main(int argc, const char * argv[]) {
game = new Game();
game->init("Birchengine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, false);
while (game->running()) {
game->handleEvents();
game->update();
game->render();
}
game->clean();
return 0;
}
What could be the cause of this error, and how do I prevent it in the future?

SDL2 errors what am I doing Wrong

It was working before I tried to load my image.
This is the error I get:
Error 1 error LNK2005: "struct SDL_Window * m_pWindow"
(?m_pWindow##3PAUSDL_Window##A) already defined in
Game.obj C:\Users\Joseph\Desktop\DuckGotti\DuckGotti\maine.obj
Error 2 error LNK2005: "struct SDL_Renderer * m_pRenderer"
(?m_pRenderer##3PAUSDL_Renderer##A) already defined in
Game.obj C:\Users\Joseph\Desktop\DuckGotti\DuckGotti\maine.obj
Error 3 error LNK2005: "struct SDL_Texture * m_pTexture"
(?m_pTexture##3PAUSDL_Texture##A) already defined in
Game.obj C:\Users\Joseph\Desktop\DuckGotti\DuckGotti\maine.obj
Error 4 error LNK2005: "struct SDL_Rect m_sourceWREK"
(?m_sourceWREK##3USDL_Rect##A) already defined in
Game.obj C:\Users\Joseph\Desktop\DuckGotti\DuckGotti\maine.obj
Error 5 error LNK2005: "struct SDL_Rect m_destWREK"
(?m_destWREK##3USDL_Rect##A) already defined in
Game.obj C:\Users\Joseph\Desktop\DuckGotti\DuckGotti\maine.obj
Error 7 error LNK1169: one or more multiply defined symbols found
C:\Users\Joseph\Desktop\DuckGotti\Debug\DuckGotti.exe 1
Here is my code (main.cpp):
#include <SDL.h>
#include <SDL_image.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include "Game.h"
/**my first game obj**/
Game* g_game = 0;
int main(int argc, char* argv[])
{
g_game = new Game();
g_game->init("Duck Gotti", 100, 100, 640, 480, SDL_WINDOW_FULLSCREEN );
while (g_game->running())
{
g_game->handelEvents();
g_game->update();
g_game->render();
}
g_game->clean();
return 0;
}
Game.h
#ifndef __Game__
#define __Game__
#include <SDL.h>
#include <SDL_image.h>
#include <stdio.h>
#include <string>
#include <iostream>
SDL_Window* m_pWindow;
SDL_Renderer* m_pRenderer;
SDL_Texture* m_pTexture;
SDL_Rect m_sourceWREK;
SDL_Rect m_destWREK;
class Game
{
public:
Game(){}
~Game(){}
/**setting the run var to true**/
bool init(const char* title, int xpos, int ypos, int width, int height
,bool fullscreen);
void render();
void update();
void handelEvents();
void clean();
/** a func to access the privet var **/
bool running() { return m_bRunning; }
private:
SDL_Window* m_pWindow;
SDL_Renderer* m_pRenderer;
bool m_bRunning;
};
#endif /**defined (__Game__) **/
Game.cpp:
#include "game.h"
bool Game::init(const char* title, int xpos, int ypos, int width,
int height, bool fullscreen )
{
int flags = 0;
if (fullscreen)
{
flags = SDL_WINDOW_FULLSCREEN;
}
/**attempt to initalize SDL**/
if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
std::cout << "SDL init sucess/n";
/**init the winn**/
m_pWindow = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
if (m_pWindow !=0)
{
std::cout << "window creation sucess/n";
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
if (m_pRenderer != 0)
{
std::cout << "renderer created/n";
SDL_SetRenderDrawColor(m_pRenderer, 255, 255, 255, 255);
}
else
{
std::cout << "renderer broked/n";
return false;
}
}
else
{
std::cout << "winn init nope/n";
return false;
}
}
else
{
std::cout << "SDL init broked/n";
return false;
}
std::cout << "init sucess/n";
m_bRunning = true;
return true;
SDL_Surface* pTempSurf = SDL_LoadBMP("img3.bmp");
m_pTexture = SDL_CreateTextureFromSurface(m_pRenderer, pTempSurf);
SDL_FreeSurface(pTempSurf);
SDL_QueryTexture(m_pTexture, NULL, NULL, &m_sourceWREK.w, &m_destWREK.h);
m_destWREK.x = m_sourceWREK.x = 0;
m_destWREK.y = m_sourceWREK.y = 0;
m_destWREK.w = m_sourceWREK.w;
m_destWREK.h = m_sourceWREK.h;
}
void Game::render()
{
SDL_RenderClear(m_pRenderer);
SDL_RenderCopy(m_pRenderer, m_pTexture, &m_sourceWREK, &m_destWREK);
SDL_RenderPresent(m_pRenderer);
}
void Game::update()
{
}
void Game::handelEvents()
{
SDL_Event evil;
if (SDL_PollEvent(&evil))
{
switch (evil.type)
{
case SDL_QUIT:
m_bRunning = false;
break;
default:
break;
}
}
}
void Game::clean()
{
SDL_DestroyWindow(m_pWindow);
SDL_DestroyRenderer(m_pRenderer);
SDL_Quit();
}
I believe you are reading this book SDL Game Development. Be aware, the book has a bunch of errors.
remove these lines
SDL_Window* m_pWindow;
SDL_Renderer* m_pRenderer;
SDL_Texture* m_pTexture;
SDL_Rect m_sourceWREK;
SDL_Rect m_destWREK;
They are already defined inside game class.
I was reading this book, luckily I was organized and I kept the files. It seems you are in the first chapter
main.cpp
#include "game.h"
Game* g_game = 0;
int main(int argc, char* args[])
{
g_game = new Game();
g_game->init("Chapter 1: Setting up SDL", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
while( g_game->running() ){
g_game->handleEvents();
g_game->update();
g_game->render();
SDL_Delay(10);
}
g_game->clean();
return 0;
}
game.h
#ifndef _GAME_H
#define _GAME_H
#include "SDL.h"
class Game
{
public:
Game() {}
~Game() {}
bool init(const char* title, int xpos, int ypos, int height, int width, int flags);
void render();
void update();
void handleEvents();
void clean();
bool running() { return m_bRunning; }
private:
SDL_Window* m_pWindow;
SDL_Renderer* m_pRenderer;
bool m_bRunning;
};
#endif /* defined(_GAME_H) */
game.cpp
#include "game.h"
#include <iostream>
bool Game::init(const char* title, int xpos, int ypos, int height, int width, int flags)
{
if ( SDL_Init(SDL_INIT_EVERYTHING) == 0 ){
std::cout << "SDL init success\n";
m_pWindow = SDL_CreateWindow(title, xpos, ypos, height, width, flags);
if ( m_pWindow != 0 ){
std::cout << "window creation success \n";
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
if ( m_pRenderer != 0 ){
std::cout << "renderer creation success\n";
SDL_SetRenderDrawColor(m_pRenderer, 0, 0, 0, 255);
}else{
std::cout << "renderer init fail\n";
return false;
}
}else{
std::cout << "window init fail\n";
return false;
}
}else{
std::cout << "SDL init fail\n";
return false;
}
std::cout << "init success\n";
m_bRunning = true;
//#####################################################################################
return true;
}
void Game::render()
{
SDL_SetRenderDrawColor(m_pRenderer, 0, 0, 0, 255);
SDL_RenderClear(m_pRenderer);
SDL_RenderPresent(m_pRenderer);
}
void Game::clean()
{
std::cout << "cleaning game\n";
SDL_DestroyWindow(m_pWindow);
SDL_DestroyRenderer(m_pRenderer);
SDL_Quit();
}
void Game::handleEvents()
{
SDL_Event event;
if ( SDL_PollEvent(&event) ){
switch( event.type ){
case SDL_QUIT:
m_bRunning = false;
break;
default:
break;
}
}
}
void Game::update()
{
}
These are some notes I've written
After chapter 2, you need to organize your classes because you will get lost easily with the inheritance. For example, the below picture, you will see the way classes are connected in chapter 3
For chapter 4,
Hope this helps.

SDL error LNK1120 & LNK2019

I'm trying to compile a simple SDL example from a book and I'm getting these errors. I'm near positive everything is linked correctly, because I was able to get other SDL examples to compile fine. I'm using Visual Studio 2013.
This code was intended for use with SDL 2.0 and links to SDL.lib, while I'm using SDL 2.0.3 and linking to SDL2.lib. However, I don't see any reason why that affect anything here.
Game.cpp
#include "Game.h"
#include <iostream>
Game::Game()
{
}
bool Game::init(const char* title, int xpos, int ypos, int width,
int height, int flags)
{
// attempt to initialize SDL
if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
std::cout << "SDL init success\n";
// init the window
m_pWindow = SDL_CreateWindow(title, xpos, ypos,
width, height, flags);
if (m_pWindow != 0) // window init success
{
std::cout << "window creation success\n";
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
if (m_pRenderer != 0) // renderer init success
{
std::cout << "renderer creation success\n";
SDL_SetRenderDrawColor(m_pRenderer,
255, 255, 255, 255);
}
else
{
std::cout << "renderer init fail\n";
return false; // renderer init fail
}
}
else
{
std::cout << "window init fail\n";
return false; // window init fail
}
}
else
{
std::cout << "SDL init fail\n";
return false; // SDL init fail
}
std::cout << "init success\n";
m_bRunning = true; // everything inited successfully,start the main loop
return true;
}
void Game::render()
{
SDL_RenderClear(m_pRenderer); // clear the renderer to the draw color
SDL_RenderPresent(m_pRenderer); // draw to the screen
}
void Game::handleEvents()
{
SDL_Event event;
if (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
m_bRunning = false;
break;
default:
break;
}
}
}
void Game::clean()
{
std::cout << "cleaning game\n";
SDL_DestroyWindow(m_pWindow);
SDL_DestroyRenderer(m_pRenderer);
SDL_Quit();
}
Game.h
#ifndef __Game__
#define __Game__
#include "SDL.h"
class Game
{
public:
Game();
~Game();
bool init(const char* title, int xpos, int ypos, int width, int
height, int flags);
void render();
void update();
void handleEvents();
void clean();
bool running() { return m_bRunning; }
private:
SDL_Window* m_pWindow;
SDL_Renderer* m_pRenderer;
bool m_bRunning;
};
#endif /* defined(__Game__) */
Main.cpp
#include "Game.h"
// our Game object
Game* g_game = 0;
int main(int argc, char* argv[])
{
g_game = new Game();
g_game->init("Chapter 1", 100, 100, 640, 480, 0);
while (g_game->running())
{
g_game->handleEvents();
g_game->update();
g_game->render();
}
g_game->clean();
return 0;
}
And the following are the errors/warnings I recieve:
Error 3 error LNK1120: 1 unresolved externals c:\users\alexn\documents\visual studio 2013\Projects\SDL_template2\Debug\SDL_template2.exe SDL_template2
Error 2 error LNK2019: unresolved external symbol "public: void __thiscall Game::update(void)" (?update#Game##QAEXXZ) referenced in function _SDL_main c:\Users\alexn\documents\visual studio 2013\Projects\SDL_template2\SDL_template2\Main.obj SDL_template2
Warning 1 warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library c:\Users\alexn\documents\visual studio 2013\Projects\SDL_template2\SDL_template2\MSVCRTD.lib(cinitexe.obj) SDL_template2
You're calling Game::update() from your main(), however it seems that you didn't actually implement it.
As for the warning, refer to this question for more info. It's likely that you're trying to link with a version of SDL (or some other lib) that was built with a different C runtime.

SDL + C++ Error: LNK2019 unresolved external symbol_SDL_main referencedin function

I Google-d this problem and viewed at least 20 threads about this and tried different solutons but none worked out.This code is in SDL 2.0.3 in Visual Studio 2013 Express. Here is my code:
#include <iostream>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
class MGGMain{
int player_x;
int player_y;
int player_w = 50;
int player_h = 50;
SDL_Rect player_rect;
SDL_Texture* player_text;
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Event* mainEvent;
bool quit;
void Init()
{
}
void LoadAssets(SDL_Renderer* renderer)
{
//IMG_LoadTexture(renderer, <path>);
player_text = IMG_LoadTexture(renderer, "images/dev/dev_player");
}
void Update()
{
int player_x;
int player_y;
SDL_Rect player_rect = CreateRect(player_h, player_w, player_x, player_y);
if (mainEvent->type == SDL_QUIT)
{
quit = true;
}
}
void Draw(SDL_Renderer* renderer)
{
//SDL_RenderCopy(renderer, <texture>, <rect>)
SDL_RenderCopy(renderer, player_text, &player_rect, &player_rect);
}
SDL_Rect CreateRect(int h, int w, int x, int y)
{
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.h = h;
rect.w = w;
return rect;
}
int main(int argc, char* argv[])
{
std::cout << "Initialyzing SDL..." << std::endl;
SDL_Init(SDL_INIT_EVERYTHING);
std::cout << "All initialyzed, creating window and event system..." << std::endl;
window = SDL_CreateWindow("MGG", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1200, 700, SDL_WINDOW_SHOWN);
std::cout << "All succeded!" << std::endl;
quit = false;
if (window = NULL){
std::cout << "SDL Error: Window couldn't be created!" << std::endl;
return 0;
}
std::cout << "Creating renderer..." << std::endl;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
std::cout << "Renderer creation success, beginning main loop." << std::endl;
mainEvent = new SDL_Event();
LoadAssets(renderer);
Init();
while (!quit)
{
SDL_PollEvent(mainEvent);
Update();
SDL_RenderClear(renderer);
Draw(renderer);
SDL_RenderPresent(renderer);
}
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
delete mainEvent;
return 0;
}
};
Your program has no main() function.
The main function in your code is inside class MGGMain, so it becomes MGGMain::main(). It needs to be simply main(), in the highest scope, that is, outside any classes or the compiler will not find it.
SDL errors out because it overrides the main used by SDL programs to do some initializations and then calls the real main(), but since there is no main(), it throws unresolved external symbol error.