views:

91

answers:

1

Hello, 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

+2  A: 

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.

Ivan Vučica