Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linker error _SDL_main unresolved in _main_getcmdline [duplicate]

I'm following LazyFoo's tutorial for SDL2. I went through the first ten lessons, and now i'm getting this error (until i compile i don't get any errors from VS).

1>------ Inizio compilazione: Progetto: yetANewSDLProj, Configurazione: Debug Win32 ------
1>SDL2main.lib(SDL_windows_main.obj) : error LNK2019: riferimento al simbolo esterno _SDL_main non risolto nella funzione _main_getcmdline
1>Compilazione progetto "yetANewSDLProj.vcxproj" NON COMPLETATA.
========== Compilazione: 0 completate, 1 non riuscite, 0 aggiornate, 0 ignorate ==========

"Reference to external symbol "_SDL_main" unresolved in the function "_SDL_getcmdline"

It seems to me that the error is not in my code but rather between SDL's files but i can't figure out which file supposedly Visual Studio doesn't find or why. I created a new empty project, the only code i have (one file, main.cpp) is:

#include <SDL.h>
#include <SDL_image.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cmath>

int main(int argc, char* argv[])
{
    SDL_Init(SDL_INIT_VIDEO);
    while(1){}
    SDL_Quit();
    return 0;
}

The include files are in the path: "C:\vs_dev_lib\include"
The DLL/lib files: "C:\vs_dev_lib\lib\x86"
Both paths are inserted in "VC++ Directories" (Include Directories / Library Directories).
I also copied all DLLs in both System32 and SysWOW64.
I also tried copying DLLs and .lib file in my project directory.
The headers, dll and lib files are from SDL2, SDL2 image, Mixer and TTF (in all cases development libraries for windows (Visual C++ 32/64-bit).

Linker/Input/Additional Denpendencies look like this:

SDL2.lib
SDL2main.lib
SDL2_image.lib
SDL2_ttf.lib
SDL2_mixer.lib

Linker/System/Subsystem is set to "Console(/SUBSYSTEM:CONSOLE)"

Character set is "Multibyte character set" (translated, not sure how exactly it's spelled in english).

Thanks in advance, if you need any other info let me know. Googling didn't bring me any luck, i've been stuck with this for the past two days :/

like image 778
Artoflife Avatar asked Dec 24 '22 02:12

Artoflife


1 Answers

Try defining #define SDL_MAIN_HANDLED prior to including sdl headers if you are going to manually provide an entry point.

#define SDL_MAIN_HANDLED
#include "SDL.h"

int main(int argc, char *argv[])
{
    SDL_SetMainReady();
    SDL_Init(SDL_INIT_VIDEO);
...
like image 95
user7860670 Avatar answered Dec 25 '22 15:12

user7860670