How would I get a project to run in Terminal through Xcode?
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:
- Go to the screen where you can edit the build settings.
- Under 'TARGETS' in the side menu, click on your project
- Go to the 'Build Phases' tab and click the 'Add Build Phase' button
- From the list that drops down select 'Add Run Script'
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.
Austin Moore
Updated on June 05, 2022Comments
-
Austin Moore almost 2 years
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)?