Reputation: 1412
Is it possible for me to hit run in Xcode and have my project be compiled with the g++ compiler then open a Terminal window and run it?
So pretty much I want Xcode to run these commands when I hit run:
g++ [source]
./a.out
And at some point a Terminal window will open with the program running.
How could I do this (if it's possible)?
Upvotes: 3
Views: 11232
Reputation: 6668
Actually, that is what XCode does when you hit run.
That "terminal" window is what you see in the "All output" window (was called console before XCode 4).
You can enter input in that window the same as you can a terminal window....
EDIT:
You can see the same output from your app in an actual terminal. When you run the app you will get some output like this in the "All output" window:
GNU gdb 6.3.50-20050815 (Apple version gdb-1705) (Fri Jul 1 10:44:54 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys010
[Switching to process 22261 thread 0x0]
Note the tty, in this example it is /dev/ttys010
Now, open a terminal window and cat the tty:
cat /dev/ttys010
You will now see output from your program in that terminal window.
Upvotes: 0
Reputation: 1412
I had to settle with running my program in a Terminal window that I kept open while coding in Xcode. I had Xcode compile the program to an 'a.out' file whenever I built the program in Xcode. I did this by running a 'Run Script'. Here's how I did it:
Then input what you would like Xcode to do when building the program in the box under the shell command box. My commands were like this:
cd [path to program]
g++ [program]
(I can't get the block code formatting to work here).
Now all I have to do is keep a Terminal window open in the directory of the program. I run a.out
whenever I need to run the program in Terminal. Not entirely automated, but there's only one extra step than I had hoped for, which isn't too bad.
Upvotes: 2
Reputation: 1087
You can have it compile with g++ by changing the build settings (Someone else knows the specifics, i'm sure). Also, you can look at the scheme to find out where it's building the executable, from where you can use the terminal. However, I don't know why you'ed do that.. Is the debugger and log not enough?
Upvotes: 0