I have a system for building my software already set up, using a makefile and command-line tools.
I have been easily able to modify the makefile to support my Mac (10.7.4 now), so I am trying to get my code to work independently of XCode. I’ll deal with XCode once I start porting stuff to iOS. My hope is that a makefile solution (while my codebase is still manageable by said makefile) allows me better options for portability and automation.
I am experiencing exactly what is described here. The code compiles and problems are encountered on run-time.
At first I was using the SDL framework (-framework SDL) from the binary download on the SDL site, so I figured I could fix the problem by properly building SDL from source. I have done this and am now linking to libSDL.a and libSDLMain.a. This in turn requires me to include these additional frameworks to successfully compile (I came up with the list based on the output of sdl-config --static-libs:
-framework Cocoa -framework IOKit -framework AudioToolbox -framework AudioUnit -framework Carbon -framework ApplicationServices
However I still have the same problem, which the article explains has to do with missing this:
[NSApplication sharedApplication];
My code has no Obj-C code. I’m happy to plug some Obj-C into it, though. I added SDLMain.m that came with one of the packages but the linker has a problem with that: ld: duplicate symbol _main
Okay, so I’m not gonna get away with that so easy.
What’s the little piece I’m missing that will let me initialize my NSApplication? Is there a way to do it without having a separate source file (from my Main.cpp) which must now be Obj-C? Is there some C/C++ wrapper function that I can call sharedApplication with?
A lot of credit should go to RavuAlHemio because he pointed out for me enough information about what SDL is doing (trying to do) with the entry point. I then edited my code slightly, from
to
The only reason I had it the first way was because on Windows via MinGW (but not Linux) stdout and stderr were redirected to files rather than put on the terminal. I will now have to come up with a more elegant solution for that.
Anyway, this has solved the problem.