Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

blakintosh

macrumors member
Original poster
May 26, 2008
78
0
Ok guys, I was thinking if there is a script or automator app that when you drag and drop a ".cpp" file it automatically compiles it by calling "make" and then a terminal window pops up with the final executable code.

thanks in advance

ps. Right now I don't want to use IDEs, so I just want this little tool to continue using a simple text editor efficiently.
 
I'm philosophically against this in its entirety. If you want to learn to program, you need to learn how to use the tools. I don't mean that you need to learn Xcode; I mean that you need to learn Make, GCC, C++, bash, Automator, Mac OS X, etc...

First of all, only the most rudimentary of programs would actually be able to compile this way. Additionally, it promotes bad habits. Specifically, this kind of tool would provide an incentive for you to keep all code for a single program contained within a single file. This, in turn, nearly eliminates reusability, not to mention readability.

On top of all this, you're making it hard on yourself when it comes to debugging. You really don't want to try to step through a program by hand in gdb.
 
I actually agree with your point of view. The problem is that sometimes I program contest problems with c++ and later I participate on contest like that. In contests, sometimes they only give you a text editor and the console so the correct thing to do is practice using this simple tools. What I wanted was to automate part of my workflow when practicing.
 
Edit your program
Save text file
Switch to console
g++ filename.cpp
./a.out

If you're doing this multiple times with the same file you can just press the up arrow in the terminal to re-execute these same two commands, too, so it's as good as automatic.

EDIT: I believe you can also get vim to call 'make' in the background too, if you want to use that.

There's also a very nice editor by the name of TextMate which will compile and run in the background for you, offers context highlighting, indenting etc. It's a bit pricey, but from my perspective just from using it as a LaTeX frontend it's already saved me the $40-50 cost in terms of frustration with the free tools.
 
Years ago I built a script that would go through the source in a directory and build a dependancy tree / make file. I wish I knew where I put it, it's about the closest your going to get with something like this.

We inherited large bodies of code with less than enthusiastic employees during a merger years ago. They kind of threw the code over that wall so to speak and left it to us to figure out how to put it together.
 
Agree with the get comfortable with CLI thing but I got bored watching TV so here it is anyway:

http://hlynsson.com/share/DropCPP.zip

Basically just runs:
/usr/bin/g++ "$cppfile" -o ~/Desktop/CppApp
open -a Terminal ~/Desktop/CppApp

DropCPP only runs the first line, DropOpenCPP does the second one as well. Note only accepts .cpp files and is file associated with them so the apps will show up in the contextual menu under Open With....

Using it via Open With instead of as a drop on application works slower, dunno why. Also no error handling or debugging, if you need it use the CL (g++ error message can be seen in Console.app though).
 
thanks a lot Hansr, that's exactly what I was looking for. I'm amazed that you made a great little tool with a great name and icon!

Just a quick question, what do you have to learn or where can I start for creating this kind of tools?

Thanks
 
I've long thought graphic user interfaces were mixed blessings. Some computer consultants I've hired have, in my opinion, wasted their time and my money by searching for a GUI way do something they needed to do from a command-line. Although I use GUIs, I prefer command-line. So I use one often. Otherwise, I may forget how to do things that can be hard to do with a GUI. Call me weird, but GUI's sometimes annoy me thoroughly.
 
Actually with the code that Hansr posted, I modified it a bit so when I open it a terminal window pops up with the errors produced when compiling or with the running app. Then after that it asks me if I want to delete the compiled filed (using rm -i, i did my research ;) ).

This was quite interesting, I will try to learn more of this stuff.
 
Just a quick question, what do you have to learn or where can I start for creating this kind of tools?

It's based of a old (originally for 10.2) framework for building scripts to stand alone apps. And the icon is from http://www.iconarchive.com. Didn't really have to learn anything except how to create a bash script. Apple dev docs should be enough to get you started.
 
You'll need to "automate" whatever compilation flags, links, and so forth that you use. There is no easily-built "general" compilation droplet, you'll need to explicitly tell the compiler "what", and "where". Generalized make scripts quickly turn into sophisticated build/release systems, to achieve this "build & go" behavior.

Anyway, building an Applescript droplet that invokes a Bash script, which populates the fields in the make system is probably the simplest way to go (IDE-free!).
 
Actually with the code that Hansr posted, I modified it a bit so when I open it a terminal window pops up with the errors produced when compiling or with the running app. Then after that it asks me if I want to delete the compiled filed (using rm -i, i did my research ;) ).

Sounds like you're trying to reinvent the wheel here. I'm always surprised when I hear people trying to invent ways to build their code when there are lots of powerful, free and widely used build systems out there that don't rely on the use of a specific IDE (e.g. make, scons, cmake). If you continue down your current path, you will eventually wind up spending a lot of time implementing things that even the most primitive build systems already support out of the box. Plus, knowing things like Makefiles is just a good skill to have as a programmer.

If you want to get good with developing when all you have is a text editor and a console, then use the command line tools that already exist... like 'make'. If you want to use something that is more powerful and can more easily be adopted to different projects without writing the same build script over and over, then use some of the more sophisticated build systems like scons or cmake. Some of them, like cmake, will even generate unix makefiles, xcode or visual studio project files for you if you want it to (very nice build system feature for cross-platform projects). Using a bash script that invokes g++ is not the way to go unless you are building trivial, small programs (and even then I say Makefiles are better).
 
Well, they are small and trivial programs actually. I do use IDE's mainly Eclipse and I'm starting to use xcode. But when I'm playing around with programming problems and puzzles I use this little tool.

You should check out some problems at http://uva.onlinejudge.org/
 
I think people are getting a bit overboard with this thing. He obviously just wanted it for simple trivial condensed apps and it most likely took me less time to make that application droplet than for you guys to write those posts complaining about the method :p
 
I think people are getting a bit overboard with this thing. He obviously just wanted it for simple trivial condensed apps and it most likely took me less time to make that application droplet than for you guys to write those posts complaining about the method :p

That's the problem with geeks.
 
That's the problem with geeks.

The problem with geeks. Phew! I'm so glad there's only one. ;)

Everyone needs to find a toolset and workflow that works for them, but IMHO you ultimately need to learn the CLI to really understand what's going on. If even just to create and modify the droplet presented here. (As evidenced by the rm -i comment).

Just one last comment. I'm very glad to see that the OP was able to extend the tool as originally presented, though it sure would be nice if those changes were made available in the thread so others who may be interested can learn from it.

B
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.