Reputation: 53
I'm trying to use SDL with Visual Studio 2019 but my programs are only showing an empty console. At the moment I just want to be able to compile my program with the SDL libraries.
#include <iostream>
#include <SDL.h>
int main(int argc, char** argv)
{
std::cout << "yee haw!" << std::endl;
return 0;
}
This code is just giving me a console with the text:
(process 32) exited with code 0. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . .
Where I would want 'yee haw!' preceding it.
It works fine when I take out the #include <SDL.h>
(but I want the SDL.h)
I've heard that SDL now redirects to a stdout.txt file but I couldn't find that anywhere. I've also tried displaying a window with code from a tutorial I found, but that also gives me the empty console.
I'm using Visual Studio 2019 on Windows and SDL 2.0.9
Thanks!
Upvotes: 1
Views: 1627
Reputation: 1420
By default, SDL uses a macro hack to replace the main
function. The user defined main
function must be in the following format:
int main(int argc, char** argv)
{
// whatever
return 0;
}
Alternatively, if you don't want this behaviour you can use SDL_SetMainReady
.
#define SDL_MAIN_HANDLED
#include <SDL.h>
int main()
{
SDL_SetMainReady();
// whatever
return 0;
}
Upvotes: 1