SDL2 OSX Sierra "Illegal Instruction: 4"


I’ve been having a problem getting SDL2 working on OSX, both with the 32bit shared library and 64bit shared library.

When I call any SDL2 function, in this example SDL_Init, I get a terminal error with the message dumped on the console:

Illegal Instruction: 4

In my program I am using dlopen() to load the SDL2 shared library which is in the same folder as my application. I then use dlsym() to load all the SDL2 functions. Finally I proceed a point where I call SDL_Init(). It’s at that point my program exists with the message above left in the terminal.

I have been dynamically loading SDL2 on Windows, Linux, and Pi without any problems. Is there some special consideration I’m not aware of that are needed when attempting to load SDL2 this way on OSX? Perhaps linking frameworks?

I am on OSX Sierra if that helps.


Bit of a guess, but try setting the deployment target for your app to 10.6. (10.6 is the deployment target of the SDL2.framework in , assuming that is the framework you’re dlopen()ing.)


Sorry I should have replied. I fixed the issue. Part of it was related to linking an initializing apple frameworks, and the other part was the initialization of thread local storage, neither of which are something SDL2 covers. So in other words it wasn’t an SDL2 problem.