Sublime Forum

Windows C/C++/C# user questions

#1

Hi there,

Just discover sublime text 2, love it, it’s great, but need to solve a few basic blockers:
I am mainly a windows C/C++/C# user, and do not normally use make, how can I come up with a build system works for Microsoft’s cl.exe csc.exe compiler?
Also, is there a use-able perforce tools which I can edit/submit files from.to perforce?

Another thing I have noticed that it does not do code folding for XML files.

Thanks,

webcliff

0 Likes

#2

Okay, figured some of the things out, here is the build system I use:

C++

{
	"cmd": "cl.exe", "/O2", "/GL", "/W3", "/Zi", "/TP", "/EHsc", "$file"],
	"selector": "source.c++"
}

C#

{
	"cmd": "csc.exe", "/r:system.dll,system.drawing.dll", "/t:winexe", "$file"],
	"selector": "source.cs"
}
0 Likes

#3

I wanted similar functionality to the default Python builder, so my C# builder is a little more involved.

Here’s the .sublime-build file:

{
	"cmd": "\\path\\to\\sublimetext_csharp_builder.bat", "$file", "${file/\\.cs/\\.exe/}"],
	"working_dir": "${project_path:${folder:${file_path}}}",
	"file_regex": "^(...*?)(]([0-9]*),([0-9]*))]",
	"selector": "source.cs"
}

cmd: Executes a batch file wrapper around csc.exe (more in a bit). The parameters to the batch file are the source file and the name of the executable to create (it swaps the .cs extension for .exe for the name of the binary).
working_dir: The directory of the current file.
file_regex: This is used to parse line numbers in the error output so you can double-click on them to navigate to the errors in the source.

The referenced batch file does a few things: it first executes %VS90COMNTOOLS%vsvars32.bat (this is for VS 2008; replace with VS10 for VS 2010), which sets up the PATH, INCLUDE and LIB variables for the shell environment. It then executes csc.exe with the passed-in C# source file and if successful, executes the resulting binary. The last step is easily removable, but I tend to only write small, one-off console apps in SublimeText and use VS for heavier lifting so it’s useful for me. I’ve put the batch file in a Gist here: gist.github.com/1387512

0 Likes