Several years later, I have the answer to this.
In the main header file I added this definition:
#ifdef __APPLE__ #define main cppmain #endif
Declare your C++ main function just like normal and the compiler will internally rename it to "cppmain".
And then in main.mm I have the real main function:
#undef main int main(int argc, const char* args) { return NSApplicationMain(); } #define main cppmain
And in AppDelegate.mm the C++ main function is called with arguments passed to it:
`
extern int cppmain(int argc, const char* argv[]);
- (void)applicationDidFinishLaunching:(NSNotification )aNotification {
int argc = _NSGetArgc();
char argv = _NSGetArgv();
cppmain(argc, (const char*)argv);
[NSApp terminate:self];
}
`
As a result all our existing examples work just fine with the normal main() function declared in C++:
https://www.ultraengine.com/learn/CPP/CreateTreeView
Topic:
Programming Languages
SubTopic:
General
Tags: