• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
main() in static library, cocoa + c++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

main() in static library, cocoa + c++


  • Subject: main() in static library, cocoa + c++
  • From: Ivan Galic <email@hidden>
  • Date: Mon, 21 Jan 2008 00:07:02 +0100

Hi,

we are creating a game engine which should be multi-platform. It is practically all written in C++, except for the OSX window and OpenGL initialization part which uses objective-c++.

I have created a 'cocoa static library', which contains the main() function and the message loop.
The user should create an application, which would be written in c++, and which would have to have function called NIMain() that will be called from the 'real' main in the static library.


The problem is that I don't know how to make that user's application behave like an application. The application menu doesn't show up, there is no icon in the dock, etc.

I use one 'project' with many targets, one of which is the static library 'enginemain' and one is the user's application. I have tried making it a bsd shell tool (in which case it behaves like I've described above, and the NIMain() gets called correctly - it also seems to process the event loop well), and a cocoa application. In the latter case it doesn't allow me to have a single .cpp file associated with the project - if I do, it reports 2000-4000 errors, because the c+ + compiler is trying to compile the cocoa headers. I have no idea why that happens - it doesn't if I create a new cocoa application as a new project (instead of a new target in the existing project).

The code of the enginemain goes something like this:

startup_macosx.mm:

int NIMain(); //just a declaration

int main()
{

[[NSAutoreleasePool alloc] init];

[NSApplication sharedApplication];
[NSApp setDelegate:[[[AppDelegate alloc] init] autorelease]];

[[NSBundle loadNibNamed:@"MainMenu.nib" owner:[NSApp delegate]]; // This returns true

[NSApp finishLaunching];

NSEvent *event;

while(![[NSApp delegate] isQuit])
{
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];


//Mostly do nothing
[NSApp sendEvent:event];

//Let's say we just do it like this:
NIMain(); //Returns immediately
}

return 0;


I also have the AppDelegate, which simply implements a few delegate methos like terminate, isQuit, etc.


This same code works if I create a new 'cocoa application', but not if I separate it into libraries. Also, is there a way for me to add the nib file to the library itself (currently, I just put it in the same directory as the executable)?

Sorry for the long post, I didn't know how to explain the problem shorter...


Thanks for any help, Ivan _______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Programmatic binding to Quartz Composition working in one direction
  • Next by Date: Re: Anybody using Eiffel-Cocoa?
  • Previous by thread: Programmatic binding to Quartz Composition working in one direction
  • Next by thread: Drag and Drop and Text Field Problem...
  • Index(es):
    • Date
    • Thread