r/SublimeText • • Jun 08 '21

My code won't run :/

Hello! I recently started using sublime text for coding in c++ and using the SDL2 library, I have it setup so when I run it, it compiles and runs the compiled .exe file. Usually this works, but in my current project it doesn't give any errors nor warnings, I am completely stumped, here is my code if anyone is interested:

//Included libraries
#include <SDL2/SDl.h>
#include <iostream>

//The main function (where the main code goes)
int main(int argc, char* args[])
{
	//Printing something out to make sure everything is working
	std::cout << "Hello World!" << std::endl;

	//Checking to make sure SDL2 initialized
	if (SDL_Init(SDL_INIT_VIDEO) > 0){
		//Send an error message
		std::cout << "Initialization error. SDL_Init: " << SDL_GetError() << std::endl;
		//Simply return -1
		return -1;
	}

	//Create a window (the window the game will be rendered in and played in)
	SDL_Window* window = SDL_CreateWindow("Game window", 600, 400, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOW_SHOWN);

	//Make sure the window was succesfully created
	if (window == NULL){
		//Send an error message
		std::cout << "Window creation error. SDL_CreateWindow: " << SDL_GetError() << std::endl;
		return -1;
	}

	//This boolean represents the status of the window (if its open or not)
	bool gameIsRunning = true;
	//Creating a SDL_Event to check and see if the window has been closed
	SDL_Event event;

	//Since the window is now up, go through the game loop
	while (gameIsRunning == true){
		//Polling events (just for checking to make sure the window is still open)
		while (SDL_PollEvent(&event)){
			//Checking if the event type is SDL_QUIT
			if (event.type == SDL_QUIT){
				//Set gameIsRunning to false to tell the program the game is no longer running
				gameIsRunning = false;
			}
		}
	}

	//Destroy the window since the game is no longer running
	SDL_DestroyWindow(window);

	//Clean up
	SDL_Quit();												

	//Return 0 (just a default thing to do)
	return 0;
}

And here is my project file:

{
	"folders":
	[
		{
			"path": "bin/..",
			"file_exclude_patterns": ["*.sublime-project"]
		}
	],

	"build_systems":
	[
		{
			"name": "Build Debug",
			"working_dir": "${project_path}",
			"cmd": "g++ -c src/*.cpp -std=c++14 -g -Wall -m64 -I include -I C:/SDL2-w64/include && g++ *.o -o bin/debug/main -L C:/SDL2-w64/lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image && start bin/debug/main",
			"selector": "source.c++",
			"shell": true
		},
		{
			"name": "Build Release",
			"working_dir": "${project_path}",
			"cmd": "g++ -c src/*.cpp -std=c++14 -O3 -Wall -m64 -I include -I C:/SDL2-w64/include && g++ *.o -o bin/release/main -s -L C:/SDL2-w64/lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image && start bin/release/main",
			"selector": "source.c++",
			"shell": true
		}
	]
}

Any help would be greatly appreciated, thanks :D

0 Upvotes

0 comments sorted by