Openframeworks and sublime 2


#1

Anyone ever tried to replace xcode with sublime2? I really dislike xcode coding in sublime2 would be so much nicer.

I gave it a quick go. It should be possible to have build via xcodebuild fairly easy for example if I run this on the command line in my app directory :

  
xcodebuild -configuration Debug  -sdk macosx10.7  

it compiles the app fine.

I can then go into sublime and put this into a build script it compiles the app in sublime2. (http://addyosmani.com/blog/custom-sublime-text-build-systems-for-popular-tools-and-languages/)

  
  
{  
	"cmd": ["xcodebuild"],  
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",  
    "working_dir": "${project_path:${folder}}",  
	"selector": "source.c, source.c++",  
  
	"variants":  
	[  
		{  
			"name": "Run",  
			"cmd": ["bash","-c",  "${project_path:${folder}}/bin/$project_base_name.app/Contents/MacOS/$project_base_name" ]  
		}  
	]  
}  
  
  

I have this build script from here: http://forum.libcinder.org/topic/cinder-in-sublime-text-2#23286000001366165
but now I am stuck how to launch the app after the variant bit is not working, must be some path wrong?

Another amazing thing would be to use SublimeClang (https://github.com/quarnster/SublimeClang) to get autocompletions. I managed to include the lib directory of openframeworks but now get loads of errors in the sublime2 console

  
:0,0 - Fatal - too many errors emitted, stopping now [Disable with -ferror-limit=0]  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:80,11 - Error - no member named 'memcpy' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:81,11 - Error - no member named 'memmove' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:82,11 - Error - no member named 'strcpy' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:83,11 - Error - no member named 'strncpy' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:84,11 - Error - no member named 'strcat' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:85,11 - Error - no member named 'strncat' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:86,11 - Error - no member named 'memcmp' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:87,11 - Error - no member named 'strcmp' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:88,11 - Error - no member named 'strcoll' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:89,11 - Error - no member named 'strncmp' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:90,11 - Error - no member named 'strxfrm' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:91,11 - Error - no member named 'strcspn' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:92,11 - Error - no member named 'strspn' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:93,11 - Error - no member named 'strtok' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:94,11 - Error - no member named 'memset' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:95,11 - Error - no member named 'strerror' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:96,11 - Error - no member named 'strlen' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:98,11 - Error - no member named 'memchr' in the global namespace  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:102,12 - Error - no matching function for call to 'memchr'  
  

anyway anyone interested in helping figuring this out? Seems like the solution is not too far away.

Tommi


#2

ok I got pretty close, this is the correct build command in sublime2

  
  
{  
	"cmd": ["xcodebuild"],  
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",  
    "working_dir": "${project_path:${folder}}",  
	"selector": "source.c, source.c++",  
  
	"variants":  
	[  
		{  
			"name": "Run",  
			"cmd": ["bash","-c", "'${project_path}/bin/${project_base_name}.app/Contents/MacOS/${project_base_name}'" ]  
		}  
	]  
}  
  
  

now compiles and runs fine in sublime:

I was missing the brackets in the bash command before. Now just need to get sublime clang to work, it needs all the same include files as OF needs in xcode. I included everything from the “CoreOF.xcconfig” file, but there must be some other ones I am missing as I get errors about pretty basic things missing:

  
  
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/cstring:80,11 - Error - no member named 'memcpy' in the global namespace  

Any other libs I would need to include?


#3

Hi Thomas - that’s exciting work, indeed!

Maybe the namespace errors are related to this post:

http://forum.openframeworks.cc/t/tons-of-quot;no-member-in-global-spacequot;-errors/11096/1

Which boils down to POCO having its own “String.h” file which might take precedence over the standard library’s <string.h>…

Cheers
#

Tim


#4

Nice! This is my Sublime build script.

  
  
{  
  "cmd": ["xcodebuild"],  
  "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",  
  "working_dir": "${file_path}/../",  
  "selector": "source.c, source.c++, source.cpp, source.h"  
}  
  

I’d much rather use gcc instead of xcodebuild, and I’d also like to add code hinting and syntax highlighting, which is a separate plugin but an oF-Subl plugin could include an oF-Subl build system. That’d be rad. Than we could have a pro build environment that’s not xcode.

Oh, I’m running 10.6 not sure if that build script works on 10.7+


#5

Hi all,

I got it to work, with code completion and all. It’s a really sweet system, the code completion is quite nice since it uses Sublime’s unsharp matching =)

Here is my sublime-project file (you need one for every project in the project’s base directory to configure code completion).
Note that I had to set absolute paths for the addons I am using, I tried to figure out how to use relative paths, but gave up after a while.

  
  
{  
	"folders":  
	[  
		{  
			"path": "/Developer/dev/oF/apps/dev/sketchMeshTypo"  
		}  
	],  
	"settings":  
	{  
		"sublimeclang_enable_fast_completions": true,  
//		"add_language_option": true,  
//		"additional_language_options":  
//  		  	{  
//					// For example, you can use "c++": ["-std=c++11"] to enable C++11 features.  
//					"c++" : ["-std=c++11"],  
//					"c": [],  
//					"objc": [],  
//					"objc++": []  
//				},  
		"sublimeclang_options":  
		[  
			"-Isystem",  
			"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/",  
			"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/c++/4.2.1/",  
			"-Wno-deprecated-declarations",  
			"-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks",  
			"-I/Developer/dev/oF/libs/**",  
			"-I/Developer/dev/oF/addons/ofxGui/**",  
			"-I/Developer/dev/oF/addons/ofxXmlSettings/**",  
			"-I/Developer/dev/oF/addons/ofxSvg/**",  
			"-I/Developer/dev/oF/addons/ofxAssimpModelLoader/**"  
		]  
	}  
}  
  

And here’s my build system (it uses ‘open’ to call the app which puts it in the foreground) remove ‘open’ if you’d rather not have this behaviour.

  
  
{  
	"cmd": ["xcodebuild"],  
	"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",  
	"working_dir": "${project_path:${folder}}",  
	"selector": "source.c, source.c++",  
  
	"variants":  
	[  
		{  
			"name": "Run",  
			"cmd": ["bash","-c", "open ${project_path:${folder}}/bin/$project_base_name.app/Contents/MacOS/$project_base_name" ]  
		}  
	]  
}  
  

Another thing I noticed is that Sublime is quite moody about gremlins (trailing whitespace characters being not tabs etc.) in its configuration files, so these might need a bit of tweaking, depending on how faithful the forum software will preserve the ‘code’ sections I pasted.

Good luck!
#

Tim


#6

Hey Tim,

nice one. its odd, as far as I can see I have pretty much the same settings for sublimeclang. I am on 10.7 so maybe thats why.

If you change your open to

  
"open '${project_path:${folder}}/bin/$project_base_name.app/Contents/MacOS/$project_base_name' " ]  

it should also work with spaces in project names, at least that was a problem I ran into.

if you want the local folder in your sublimeclang settings you should be able to use ${project_path:${folder}} so something like

  
"-I/${project_path}/../../../libs/openFrameworks/**"  

should work.

really annoyed I cant get it to work!


#7

Hi Thomas,

thanks for the quotes around ‘open’ hint - very useful!

Have you tried the project file I pasted? You’d need to adjust for the 10.7 sdk, though. And the double ‘**’ are really important, for it means to recursively include the directories, also the order of inclusion makes a difference.

Cheers
#

T


#8

yeah,

thats what mine looks like:

  
  
{  
	"folders":  
	[  
		{  
			"path": "/Users/tommi/Documents/of_0071_osx_release/examples/empty/emptyExample copy"  
		}  
	],  
	"settings":  
	{  
			"sublimeclang_enable_fast_completions": true,  
			"sublimeclang_options":  
			[  
					"-Isystem",  
					"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/",  
					"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/",  
					"-Wno-deprecated-declarations",  
					"-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks",  
					"-I/Users/tommi/Documents/of_0071_osx_release/libs/**"  
			]  
	}  
}  
  
  


#9

that looks quite ok to me - what kind of errors do you get? And just to rule out the obvious: you did clean the cache by hitting ALT+D then ALT+C, right?


#10

Hey Tim,

somehow now it works. reinstalled sublimeclang and added the settings to the sublimeclang user file (shift + apple + p, then sublimeClang… and select the user settings, then I pasted :

  
  
  
{  
		"options":  
		[  
				"-Isystem",  
				"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/",  
				"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1/",  
				"-Wno-deprecated-declarations",  
				"-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks",  
				"-I/Users/tommi/Documents/of_0071_osx_release/libs/**"  
		]  
}  
  
  

and it works! weird, wish I knew what didnt work before… My sublime project file didnt work for some reason

its really cool. such fast code completion


#11

Fantastic! Thanks for starting this thread, I’ll be much happier now coding on Sublime, specially in Linux. Will post updates if Linux needs some extra love. =)


#12

well on linux you should be able to leverage the working makefile infrastructure, right? not so much config should be necessary. hopefully coming soon to mac, too. hopefully for you guys, i mean :wink:

Also, was it you tim who posted the link to that possibility of having gcc without xcode? could simplify things even more: http://osxdaily.com/2012/07/06/install-gcc-without-xcode-in-mac-os-x/


#13

t’was indeed me - and Sublime Text on OSX seems to be working =)

*
With linux the build w/ makefile part should be a piece of Sachertorte, it’s more the code completion (sublime project settings) that will need a little tweaking.


#14

great to hear. report back with your linux results bittschen, i’ve been wanting to try out sublimetext for quite some time now (with all the praise people seem to give it).


#15

Dankeschön! I’ll give this a spin asap.
Regarding compiling sublimeclang instead of using the packagemanager - is there a not-yet-released bug or does this have some other deeper reason.

regarding -Wno-deprecated-declarations - you do realise that you won’t see the deprecation messages we carefully include nowadays to warn users that they are using old functions, right? :slight_smile:


#16

Bittesehr, bitte gern:

I can confirm that Sublime2 with code completion works on ubuntu 12.04.

The makefile based build system was a piece of cake as expected, and to get sublimeclang codecompletion to work needs a bit of tweaking, but is definitely worth the effort.

Here’s my Linux build system file:

  
  
// file of.sublime-build  
{  
	"cmd": ["make"],  
	"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",  
	"working_dir": "${project_path:${folder}}",  
	"selector": "source.c, source.c++",  
  
	"variants":  
	[  
		{  
			"name": "Run",  
			"cmd": ["bash","-c", "${project_path:${folder}}/bin/$project_base_name" ]  
		}  
	]  
}  
  

As for getting SublimeClang code completion to work, do not install with the Sublime Text Package manager, but install SublimeClang from git following the instructions on:

https://github.com/quarnster/SublimeClang#readme

This also means to manually compile libcache.

After that finished, I had to use Sublime’s package manager to first Disable, then Enable the Sublime clang package again.

Here’s my sublime-project file with all options I had to set to get SublimeClang to find the right headers:

  
  
	"settings":  
	{  
		"inhibit_sublime_completions" : true,  
		"sublimeclang_enable_fast_completions": true,  
		// "add_language_option": true,  
		// "additional_language_options":  
		// 	{  
		// 			// For example, you can use "c++": ["-std=c++11"] to enable C++11 features.  
		// 			"c++" : ["-std=c++0x"],  
		// 			"c": [],  
		// 			"objc": [],  
		// 			"objc++": []  
		// 	},  
		"sublimeclang_options":  
		// [http://www.sublimetext.com/forum/viewtopic.php?f=6&t=9313](http://www.sublimetext.com/forum/viewtopic.php?f=6&t=9313)  
  
		[  
			"-Wno-deprecated-declarations",  
			"-I/usr/include/gstreamer-0.10/",  
			"-I/usr/include/glib-2.0/",  
			"-I/usr/lib/i386-linux-gnu/glib-2.0/include",  
			"-I/home/tim/Documents/labs/of/libs/**",  
  
			"-I/home/tim/Documents/labs/of/addons/ofxGui/**",  
			"-I/home/tim/Documents/labs/oF/addons/ofxXmlSettings/**"  
		]  
	}  
}  
  

Be aware of gremlins when copying these snippets, and make sure the JSON in the Sublime configuration files is saved UTF-8, with tabs instead of spaces.

note that some of the options could go into the Global or User Sublimeclang configuration file, and the project file then would only really need to link the addon directories.

Finding the right cflags was the trickiest part, until I found that on ubuntu this:

  
  
# find out the linker flags for library glib-2.0:  
pkg-config --cflags --libs glib-2.0   
  

gives you the correct header locations.

oF with SublimeText on Linux is so much fun (and it’s quick & snappy, too)!

Good luck!
#

Tim


#17

Hey folks,

a quick update - managed to get c++11 going with sublimetext and sublimeclang.

  
  
{  
	"folders":  
	[  
		{  
			"path": "/home/tim/Documents/labs/of/apps/of-dev/myProject"  
		},  
		{  
			"path": "/home/tim/Documents/labs/of/addons/myAddon"  
		}  
	],  
	"settings":  
	{  
		"add_language_option": true,  
		"additional_language_options":  
		{  
			"c":  
			[  
			],  
			"c++":  
			[  
				  
			],  
			"objc":  
			[  
			],  
			"objc++":  
			[  
			]  
		},  
		"inhibit_sublime_completions": true,  
		"sublimeclang_enable_fast_completions": true,  
		"sublimeclang_options":  
		[  
			"-std=c++11",  
			"-stdlib=libc++",  
			// "-Wno-c++11-extensions",  
			"-I/usr/include/c++/4.6.3/",  
			"-I/usr/include/c++/4.6.3/i686-linux-gnu/",  
			"-I/usr/include/c++/4.6.3/ext/",  
			"-I/usr/include/gstreamer-0.10/",  
			"-I/usr/include/glib-2.0/",  
			"-I/usr/lib/i386-linux-gnu/glib-2.0/include",  
			"-I/home/tim/Documents/labs/of/libs/**"  
		]  
	}  
}  
  

And for the build makefile based build system to work with c++11, I added :

  
USER_CFLAGS = -std=c++0x  

to config.makefile.


#18

Thanks for the effort. Sublime is 10x better than xcode, and my preference as well. One thing, though…

Building works great

Running, not so much for me

Using this as part of my build script:

“cmd”: [“bash”,"-c", “open ${project_path:${folder}}/bin/$project_base_name.app/Contents/MacOS/$project_base_name” ]

or this

“cmd”: [“bash”,"-c", “open ${project_path:${folder}}/bin/${project_base_name}.app/Contents/MacOS/${project_base_name}” ]

I get this error:

The file /Users/justdayan/Documents/dev/cpp/of_0071_osx_release/examples/3d/advanced3dExample/bin/.app/Contents/MacOS does not exist.
[Finished in 0.0s with exit code 1]


For some reason $project_base_name is not expanding. I’m on 10.6.8 … Anyone else experiencing this?


#19

hi justdayan,

had the same problem, sometimes it worked sometimes it didn’t. I realized I used the dev-builds of sublime 2 and reinstalled using the main download from the site and it worked after.

T


#20

hey

I recently bought sublime. Are you still using it with of and what is the newest plugin code? Any updates to the info in this thread?

thanks