如何在 MacOSX 下的 Ogre 项目中获得输出控制台?

发布于 2024-08-06 10:37:40 字数 259 浏览 13 评论 0原文

我正在开发一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昨迟人 2024-08-13 10:37:40

从 UNIX 的角度来看,因为我在 Mac 特定的开发方面没有那么丰富的经验。

默认情况下,控制台是“分配”的。但您无法命令操作系统打开控制台。您可以告诉您正在使用的 IDE 在终端中打开它,或者,如果它支持,则将当前应用程序创建为控制台应用程序,尽管使用 GUI。

默认分配控制台是什么意思?每个进程实际上从调用进程获取其 stdinstdoutstderr(文件标识符 0、1 和 2)。因此,除非调用进程(bash、Finder,等等)方便地忘记保持这些打开状态,否则您始终会打开一个控制台......但也许不可见?

获取控制台的最简单方法是从终端启动应用程序,就像 Finder 从 GUI 中启动应用程序一样。请记住,.apps 实际上是文件夹:

/projects/myapp$ ./BuiltApplication.app/Contents/MacOS/BuiltApplication

Finder 将当前工作目录设置为 .app 包所在的文件夹,因此上面的内容最好地模拟了它。

此外,请查看 MacOS 附带的位于 /Applications/Utilities/Console.app 的控制台应用程序。控制台通常用于查看 stdout 和 stderr。我无法对此进行测试,因为我不在 Mac 上,但我实际上发现了一些消息来源说 stdout 和 stderr 应该重定向到那里。 查看这篇文章

您可以使用 Console.app 查看以正常方式启动的应用程序的输出,因为启动基础架构专门将其 stdoutstderr 发送到那里。您还可以使用 asl 例程来查询日志,或者根据需要执行更复杂的日志记录。

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 and stderr (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:

/projects/myapp$ ./BuiltApplication.app/Contents/MacOS/BuiltApplication

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:

You can use Console.app to see the output of applications launched in the normal manner, because the launch infrastructure specifically sends their stdout and stderr there. You can also use the asl routines to query the log, or perform more sophisticated logging if you so desire.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文