Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVS2015 keeps giving "unresolved externals" error with SDL2

Tags:

c++

sdl

i'm trying to make SDL work with my MVS2015 without success so far, i really want to get this to work, so i'll explain every step i made. First i downloaded the prebuild SDL2 library from the SDL installation guide: https://wiki.libsdl.org/Installation , then unpacked. Made a new console application in MVS2015, opened the project property page and set the "Include Directories" correctly, i triple checked it, also did this for "Library Directories". Then i went to "Linker" -> "Input" and added SDL2.lib to "Additional Dependencies". So far so good, my code should work with SDL now right? I made a short main to test if it works:

#include <SDL.h>
int main(){ 
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();
return 0;}

And if i build it i get these error messages:

Severity    Code    Description Project File    Line
Error   LNK1120 1 unresolved externals  sdltry4 c:\users\myuser\documents\visual studio 2015\Projects\sdltry4\Debug\sdltry4.exe 1
Error   LNK2019 unresolved external symbol _WinMain@16 referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ)   sdltry4 c:\Users\Bandan\documents\visual studio 2015\Projects\sdltry4\sdltry4\MSVCRT.lib(exe_winmain.obj)   1

Would really appriciate the help.

like image 504
Broccholio Avatar asked Feb 08 '23 10:02

Broccholio


1 Answers

You need to add this define before including the main SDL header:

#define SDL_MAIN_HANDLED
#include "SDL.h"

SDL.h includes SDL_main.h, which has an interesting bit about wanting to use its own WinMain definition, which can be disabled, since you have your own main.

like image 162
Chris O Avatar answered Feb 10 '23 23:02

Chris O