如何在 MacOSX 下的 Ogre 项目中获得输出控制台?
我正在开发一个使用 Ogre3D 的项目。我们最近将我们的项目移植到 MacOSX,但有一些东西链接到 Windows API。特别是我不知道应该如何翻译:
#if defined( __WIN32__ ) || defined( _WIN32 )
AllocConsole();
#endif
有一天将项目移植到 Linux 下会很好,那么是否有一种与 Unix 兼容的方法来为标准输出/输入分配控制台?
谢谢
I'm working on a project using Ogre3D. We recently ported our project to MacOSX but there are some things that were linked to the Windows API. In particular I don't know how this should be translated:
#if defined( __WIN32__ ) || defined( _WIN32 )
AllocConsole();
#endif
It would be nice to port the project under Linux someday, so is there an Unix-compatible way to allocate a console for standard output/input?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 UNIX 的角度来看,因为我在 Mac 特定的开发方面没有那么丰富的经验。
默认情况下,控制台是“分配”的。但您无法命令操作系统打开控制台。您可以告诉您正在使用的 IDE 在终端中打开它,或者,如果它支持,则将当前应用程序创建为控制台应用程序,尽管使用 GUI。
默认分配控制台是什么意思?每个进程实际上从调用进程获取其
stdin
、stdout
和stderr
(文件标识符 0、1 和 2)。因此,除非调用进程(bash
、Finder,等等)方便地忘记保持这些打开状态,否则您始终会打开一个控制台......但也许不可见?获取控制台的最简单方法是从终端启动应用程序,就像 Finder 从 GUI 中启动应用程序一样。请记住,.apps 实际上是文件夹:
Finder 将当前工作目录设置为 .app 包所在的文件夹,因此上面的内容最好地模拟了它。
此外,请查看 MacOS 附带的位于
/Applications/Utilities/Console.app
的控制台应用程序。控制台通常用于查看 stdout 和 stderr。我无法对此进行测试,因为我不在 Mac 上,但我实际上发现了一些消息来源说 stdout 和 stderr 应该重定向到那里。 查看这篇文章:From UNIX point of view, since I'm not that experienced in Mac-specific development.
A console is "allocated" by default. You cannot order the OS to open a console though. You could tell the IDE you are using to open it in a terminal, or, if it supports that, create your current application as a Console Application, despite using GUI.
What do I mean by saying that console is allocated by default? Each process actually gets its
stdin
,stdout
andstderr
(file identifiers 0, 1 and 2) from the calling process. So unless calling process (bash
, Finder, whatever) conveniently forgets to leave those open, you always have a console open ... but perhaps invisible?Easiest way to get a console is to launch the application from Terminal as Finder would do it from GUI. Remember, .apps are actually folders:
Finder sets the current working directory to the folder where the .app bundle is located, so the above emulates it all best.
Additionally, take a look at the Console application at
/Applications/Utilities/Console.app
, included with MacOS. Console is usually used for viewing stdout and stderr. I cannot test this since I'm not on Mac, but I've actually found some sources that say that stdout and stderr should be redirected there. See this post: