如何通过 Xcode 在终端中运行项目?
我是否可以在 Xcode 中点击运行并使用 g++ 编译器编译我的项目,然后打开终端窗口并运行它?
所以当我点击运行时,我非常希望 Xcode 运行这些命令:
g++ [source]
./a.out
并且在某个时刻,终端窗口将打开,程序正在运行。
我怎样才能做到这一点(如果可能的话)?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不得不在 Xcode 中编码时保持打开的终端窗口中运行我的程序。每当我在 Xcode 中构建程序时,我都会让 Xcode 将程序编译为“a.out”文件。我通过运行“运行脚本”来做到这一点。我是这样做的:
然后输入您想要的内容就像 Xcode 在 shell 命令框下的框中构建程序时所做的那样。我的命令是这样的:
cd [程序路径]
g++ [program]
(我无法让块代码格式在这里工作)。
现在我所要做的就是在程序目录中保持终端窗口打开。每当我需要在终端中运行程序时,我都会运行
a.out
。并非完全自动化,但只比我希望的多了一步,这还不错。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.您可以通过更改构建设置来使用 g++ 进行编译(我确信其他人知道具体细节)。另外,您可以查看该方案以了解它在何处构建可执行文件,以及您可以从何处使用终端。但是,我不知道你为什么要这样做。调试器和日志还不够吗?
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?
实际上,这就是当你点击运行时 XCode 所做的事情。
该“终端”窗口就是您在“所有输出”窗口中看到的窗口(在 XCode 4 之前称为控制台)。
您可以在该窗口中输入输入,就像在终端窗口中输入一样......
编辑:
您可以在实际终端中看到应用程序的相同输出。当您运行该应用程序时,您将在“所有输出”窗口中获得如下输出:
注意 tty,在本例中为 /dev/ttys010
现在,打开一个终端窗口并捕获 tty:
您现在将看到来自的输出您的程序在该终端窗口中。
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:
Note the tty, in this example it is /dev/ttys010
Now, open a terminal window and cat the tty:
You will now see output from your program in that terminal window.