# New Build system for mingw and sdl2

**URL:** <https://forum.sublimetext.com/t/new-build-system-for-mingw-and-sdl2/53035>\
**Category:** Technical Support\
**Created:** [August 3, 2020, 2:52pm UTC](https://forum.sublimetext.com/t/new-build-system-for-mingw-and-sdl2/53035 "2020-08-03T14:52:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Genry](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/g/7bcc69/32.png) [@Genry](https://forum.sublimetext.com/u/Genry)\
**Post date:** [August 3, 2020, 2:52pm UTC](https://forum.sublimetext.com/t/new-build-system-for-mingw-and-sdl2/53035/1 "2020-08-03T14:52:00Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![OdatNurd](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/odatnurd/32/77607_2.png) [@OdatNurd](https://forum.sublimetext.com/u/OdatNurd)\
**Post date:** [August 4, 2020, 12:26am UTC](https://forum.sublimetext.com/t/new-build-system-for-mingw-and-sdl2/53035/2 "2020-08-04T00:26:42Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![Genry](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/g/7bcc69/32.png) [@Genry](https://forum.sublimetext.com/u/Genry)\
**Post date:** [August 4, 2020, 10:25am UTC](https://forum.sublimetext.com/t/new-build-system-for-mingw-and-sdl2/53035/3 "2020-08-04T10:25:20Z")

</div>

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”,..

---

<div class="post-metadata">

**Author:** ![Dany](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@Dany](https://forum.sublimetext.com/u/Dany)\
**Post date:** [August 4, 2020, 10:46am UTC](https://forum.sublimetext.com/t/new-build-system-for-mingw-and-sdl2/53035/4 "2020-08-04T10:46:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Genry](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/g/7bcc69/32.png) [@Genry](https://forum.sublimetext.com/u/Genry)\
**Post date:** [August 4, 2020, 10:47am UTC](https://forum.sublimetext.com/t/new-build-system-for-mingw-and-sdl2/53035/6 "2020-08-04T10:47:23Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Genry](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/g/7bcc69/32.png) [@Genry](https://forum.sublimetext.com/u/Genry)\
**Post date:** [August 5, 2020, 9:29pm UTC](https://forum.sublimetext.com/t/new-build-system-for-mingw-and-sdl2/53035/7 "2020-08-05T21:29:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OdatNurd](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/odatnurd/32/77607_2.png) [@OdatNurd](https://forum.sublimetext.com/u/OdatNurd)\
**Post date:** [August 5, 2020, 10:32pm UTC](https://forum.sublimetext.com/t/new-build-system-for-mingw-and-sdl2/53035/8 "2020-08-05T22:32:53Z")

</div>

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:

```json
{
	"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:

```json
    {"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](https://www.youtube.com/playlist?list=PLGfKZJVuHW91WyVIitRhcTPD1PTFIPsia) that covers them that you may find helpful. The video on [supercharging your builds](https://youtu.be/1CkAkpNs28M) particularly talks about how the key bindings above work as well.
