Sublime Forum

New Build system for mingw and sdl2

#1

Hello, everybody!

I have a problem with my sublime. I want make a sdl2 app and for this task i create the new build system/ Here is code:

{
“cmd”: [“g++”, “${file}”,-I"C:\cpp\sdl2\include",-L"C:\cpp\sdl2\lib",-lSDL2main,-lSDL2, “-o”, “${file_path}/${file_base_name}”],
“file_regex”: “^(…[^:]):([0-9]+):?([0-9]+)?:? (.)$”,
“working_dir”: “${file_path}”,
“selector”: “source.makefile”,
“shell”: true,
“variants”:
[
{
“name”: “RunSDL2”,
“cmd”: [“g++”, “${file}”, “-o”, “${file_path}/${file_base_name}”, “&&”, “start”, “${file_path}/${file_base_name}”] ,
“shell”: true
}
]
}

but when i try to complie my simple sdl2 hello word code i cant see anything (no error, just clea console)

if i delete this text:

,-I"C:\cpp\sdl2\include",-L"C:\cpp\sdl2\lib",-lSDL2main,-lSDL2,

i have a error “where is sdl2.h file” (you know)
also in my work dir i have a Makefile. Here text:

build:
gcc -std=c99
./*.c
-I"C:\cpp\sdl2\include"
-L"C:\cpp\sdl2\lib"
-lmingw32
-lSDL2main
-lSDL2
-o example.exe

Help me please!

0 Likes

#2

The sublime-build file as you’ve posted it here is very, very broken. sublime-build files need to be valid JSON, but this is currently not:

  • The " characters are Smart Quotes (though this is likely due to the way that you shared it here; the forum didn’t realize that it should not modify it

  • Strings in JSON use the \ character to denote character escapes, but things like \c (from your first path) are not valid character escapes (and even if they were, it would not mean what you want it to mean)

  • The values in the cmd list need to be strings, but something like -L"stuff" is not a string; it’s a string with -L in front of it.

Some or all of these might be a consequence of how you pasted the build system into your forum post.

I would guess based on what you mentioned that overall your file is valid even though it doesn’t seem like it here, and the reason it works for you (sort of) when you remove some of the file is because you’re removing the part that’s broken.

As a check, note that the status bar in the window will say No Build System if the build system is invalid. You may want to pass your build through https://jsonformatter.curiousconcept.com/ or a similar service to verify that it’s valid JSON.

For what it’s worth, your build system (if it was valid) would only compile your code, so generally speaking it would either compile your program silently or complain with an error if the code was broken without actually running it. So in the case where the code was correct, likely the only thing you’d see in the build output is the [Finished] line to tell you that the build is done.

0 Likes

#3

Thx for answer! How do you fix this area?

,-I"C:\cpp\sdl2\include",-L"C:\cpp\sdl2\lib",-lSDL2main,-lSDL2,

I need to write something like this?:

["-I",“C:/cpp/sdl2/include”], “-lSDL2main”,…

0 Likes

#4

could u pls help me out as well i have posted my query as well

0 Likes

#6

As I say, I have full worked Makefile in my directory and when I past in cmd command mingw32-make i see .exe file.
So i think I need build system which just put command mingw32-make in cmd and run .exe file. May be some on give me example such system(interesting text)

0 Likes

#7

So, i make the build system that post in cmd text “mingw32-make”:

{
“cmd”: [“mingw32-make”],
“file_regex”: “^(…[^:]):([0-9]+):?([0-9]+)?:? (.)$”,
“working_dir”: “${file_path}”,
“selector”: “source.makefile”,
“shell”: true,
“variants”:
[
{
“name”: “RunSDL2”,
???
}
]
}

But now, how to create system that run my .exe file

0 Likes

#8

To do that you’d need to create a variant of the build. There’s an example of that up in the top post. If your build system has a variant in it, then you can use build with instead of build to launch the build, and Sublime will prompt you for what build to use, and you’d pick the variant. Check the Tools menu for those commands and the keys that they’re bound to on your platform.

Basically, the variant lets you have more than one way to execute something external right inside of the same file.

The build file I use for this looks like this:

{
	"shell_cmd": "make",
	"file_regex": "^(..[^:\n]*):([0-9]+):?([0-9]+)?:? (.*)$",
	"working_dir": "${file_path}",
	"selector": "source.makefile",
	"syntax": "Packages/Makefile/Make Output.sublime-syntax",
	"keyfiles": ["Makefile", "makefile"],

	"variants":
	[
		{
			"name": "Clean",
			"shell_cmd": "make clean"
		},
		{
			"name": "Run",
			"shell_cmd": "make run"
		}
	]
}

The first build is the one that knows to recognize that there’s a makefile and then execute make (I’m on Linux so my make program has a different name than yours does). Then there are also variants for Clean and Run that execute make with a different target.

With this in place, all of my Makefile's have a target to clean and a target that runs what was built (with a dependency that also actually builds it). All of my C/C++ projects use a similar Makefile structure so that no matter what I’m working on, this build will work.

I also have the following key bindings set up so that I can run either of the two variant's with the press of a key:

    {"keys": ["ctrl+alt+shift+k"], "command": "build" , "args": {"variant": "Clean"} },
    {"keys": ["ctrl+alt+shift+r"], "command": "build" , "args": {"variant": "Run"} },

If you’re unfamiliar with build systems in general, I have a video series on build systems that covers them that you may find helpful. The video on supercharging your builds particularly talks about how the key bindings above work as well.

0 Likes