Is it possible to use SDL2 with -nostartfiles?

  c++, sdl

I’ve been tinkering with SDL for the past few days and I’ve attempted to use remove main by using flags --nostartfiles and --entry _start on a project using SDL to reduce size. However, upon running the program, I get a segfault on any SDL command. The code works without these parameters with _start renamed to main.

Is it possible to remove main?

Here’s my code:

#include <SDL2/SDL.h>
#include <stdio.h>

extern "C" void _start()
{

  SDL_Window* Window = SDL_CreateWindow(NULL, 0, 0, 100, 100, 0);
  SDL_GL_CreateContext(Window);

  while (1) {
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
      switch (event.type) {
      case SDL_QUIT:
        exit(1);
        break;
      }
    }
    SDL_GL_SwapWindow(Window);
  }
  exit(0);
}

I’m using Linux and C++ if that helps.

Thanks!

Source: Windows Questions C++

LEAVE A COMMENT