0

I have been trying out SDL for iOS, and it has been going smoothly until I added sdl_ttf to the mix. The only output that I would get was

apinames 0.1: extract FreeType API names from header files

this program is used to extract the list of public FreeType API
functions. It receives the list of header files as argument and
generates a sorted list of unique identifiers

usage: apinames header1 [options] [header2 ...]

options:   -      : parse the content of stdin, ignore arguments
           -v     : verbose mode, output sent to standard error
           -oFILE : write output to FILE instead of standard output
           -dNAME : indicate DLL file name, 'freetype.dll' by default
           -w     : output .DEF file for Visual C++ and Mingw
           -wB    : output .DEF file for Borland C++
           -wW    : output Watcom Linker Response File

Upon googling, I found this SO question from someone who had the same problem as me: SDL2_ttf won't run on ios

It seems that a different main (one inside sdl_ttf) is being run and is producing the output.

  1. A commenter on the post I mentioned said "I would guess you included apinames.c in your project from the tools directory and that main is what is getting run". What is the tools directory? How would I fix that?

  2. How would I change the entry point of the Xcode project to my main.cpp?

Thanks for any advice.

Community
  • 1
  • 1

2 Answers2

0

I would have to actually see your project to answer #1 (did you look at your "compiled Sources" for apinames.c?), but maybe that will be irrelevant if I answer #2.

If you look at the SDL_main.h source file you will see:

#elif defined(__IPHONEOS__) /* On iOS SDL provides a main function that creates an application delegate and starts the iOS application run loop.

See src/video/uikit/SDL_uikitappdelegate.m for more details. */

#define SDL_MAIN_NEEDED

turns out you can subclass SDLUIKitDelegate and force SDL to instantiate it by creating a category like this:

@implementation SDLUIKitDelegate (MyDelegate)
+ (NSString *)getAppDelegateClassName
{
    //override this SDL method so an instance of our subclass is used
    return @"MyDelegateClass";
}
@end

you will want to look at the source for SDLUIKitDelegate so you can get a feel for what you are messing with, but my app just overrides application:didFinishLaunchingWithOptions: like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    AddLogger(createAppleLogger());
    [self setupWrapper];

    // Notice how we call super implementation so SDL can finish its setup
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

Is this close enough for the entry point for you? Or do you really need main()? It would mean having to do all the SDL setup yourself (which can change between SDL revisions).

Also note that your main() should get redefined as SDL_main and should get called at some point early on (if my memory serves).

Brad Allred
  • 7,323
  • 1
  • 30
  • 49
  • I bet this would be a really good answer for me if I knew Objective-C. :P Thanks anyways. –  Oct 30 '14 at 22:07
0

Drag to re-order your frameworks within "Link Binary With Libraries" found in your xcode build target under "Build Phases". Ensure that SDL2.framework (or whatever you are using) is above SDL2_image.framework.

Eamonn
  • 187
  • 2
  • 13