Skip to content

Instantly share code, notes, and snippets.

@TheSpydog
Last active October 31, 2018 02:13
Show Gist options
  • Save TheSpydog/1cfb727cf4c194cc4e6a96d5a54265ec to your computer and use it in GitHub Desktop.
Save TheSpydog/1cfb727cf4c194cc4e6a96d5a54265ec to your computer and use it in GitHub Desktop.
=======================
SDL_uikitappdelegate.m
=======================
Add this code underneath "static int exit_status;":
typedef int (*SDL_MAIN_FUNC)(void);
static SDL_MAIN_FUNC MainFunc;
extern void SetMainFunc(SDL_MAIN_FUNC func)
{
MainFunc = func;
}
Rename main to SDL_main:
int SDL_main(int argc, char **argv)
In -(void)postFinishLaunch(), change SDL_main(...) to:
MainFunc()
==============
Application.cs
==============
using System;
using System.Runtime.InteropServices;
using ObjCRuntime;
...
static void Main(string[] args)
#if __IOS__
{
realArgs = args;
SetMainFunc(FakeMain);
SDL_Main(0, IntPtr.Zero);
}
[DllImport("__Internal", EntryPoint = "SDL_main")]
static extern void SDL_Main(int argc, IntPtr argv);
[DllImport("__Internal", EntryPoint = "SetMainFunc")]
static extern void SetMainFunc(Func<int> func);
static string[] realArgs;
[MonoPInvokeCallback(typeof(Func<int>))]
static int FakeMain()
{
RealMain(realArgs);
return 0;
}
static void RealMain(string[] args)
#endif
{
// your stuff
}
=======
Linking
=======
Reference the SDL2-CS.Core project from your Application.
To link with libSDL2.a (compiled from source from SDL/Xcode-iOS/SDL), add it to your project.
Then in Project Options > iOS Build > Additional mtouch arguments, write the following:
-gcc_flags "-L${ProjectDir} -lSDL2 -force_load ${ProjectDir}/libSDL2.a -framework AVFoundation -framework AudioToolbox -framework CoreGraphics -framework Metal -framework QuartzCore -framework OpenGLES -framework GameController -framework CoreMotion -framework CoreBluetooth"
=================
SDL2-CS.dll.config
=================
Change the target for dll=SDL2 to "__Internal" so it will look in the statically-linked .a file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment