Code: Select all
#include <stdio.h>
#include <exec/exec.h>
#include <exec/types.h>
#include <dos/dos.h>
#include <dos/dostags.h>
#include <libraries/elf.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/elf.h>
#define SDL_INIT_TIMER 0x00000001
#define SDL_INIT_AUDIO 0x00000010
#define SDL_INIT_VIDEO 0x00000020 /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
#define SDL_INIT_JOYSTICK 0x00000200 /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
#define SDL_INIT_HAPTIC 0x00001000
#define SDL_INIT_GAMECONTROLLER 0x00002000 /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
#define SDL_INIT_EVENTS 0x00004000
static int (*m_SDL_Init)(ULONG flags);
int main(int argc, char *argv[])
{
struct Process *self;
BPTR seglist;
APTR result;
APTR sdllib;
Elf32_Handle elfHandle;
self = (struct Process *) FindTask(0);
seglist = GetProcSegList(self, GPSLF_CLI|GPSLF_SEG);
GetSegListInfoTags(seglist, GSLI_ElfHandle, &elfHandle, TAG_DONE);
elfHandle = OpenElfTags(OET_ElfHandle, elfHandle, TAG_DONE);
sdllib = DLOpen(elfHandle, "libSDL2.so", 0);
DLSym(elfHandle, sdllib, "SDL_Init", &result);
m_SDL_Init = result;
printf("HMM: %d\n", m_SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER|SDL_INIT_AUDIO));
DLClose(elfHandle, sdllib);
CloseElfTags(elfHandle, CET_ReClose, TRUE, TAG_DONE);
return 0;
}
Why does this not work and how can I fix it?
The ultimate goal is to be able to use libSDL2.so from a project that is linked without compiler constructor/destructor code, i.e. with the -nostartfiles option. The code above is just a test. The code above has been compiled using:
Code: Select all
gcc -D__USE_INLINE__ test.c -lauto -lpthread