#1 2017-04-04 01:47:02


SDL2 link errors on Mac

Hey guys,
  Building Tesseract on Mac with GCC/clang fails on linking with the following:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
     (maybe you meant: _mainmenu, _SDL_main )
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [client] Error 1

I have googled extensively and found it has to do with SDL2 missing its macros for renaming Tesseract's main() and calling its own. However I've only really found solutions for IDEs such as XCode by including the .m file included with SDL2 (btw my SDL2 download did not contain am .m file). I've also found suggestions of hacking the SDL2 main headers but that didn't work properly either. I can build/run Tesseract fine using XCode. Any ideas how I can fix this issue?



#2 2017-04-04 20:08:52


Re: SDL2 link errors on Mac

We found that in cube.h

  #ifdef __APPLE__
    #include "SDL2/SDL.h"
    #define GL_GLEXT_LEGACY
    #define __glext_h_
    #include <OpenGL/gl.h>
    //#define main SDL_main  // remove this
   #define SDL_MAIN_NEEDED //add this
    #include <SDL.h>
    #include <SDL_opengl.h>

What we found that sdl does this same define if we declare SDL_MAIN_NEEDED (in SDL_MAIN.h ln 94-96). This seems to be a localization error (or pickeness) and only happens on clang with mac. This is the more proper way to declare this, and should fix this error on any os (though it only seems to happen on that version of mac). We will keep posted on any extra changes that may be os dependent.


Last edited by chasester (2017-04-04 20:11:40)


#3 2017-06-10 12:59:46


Re: SDL2 link errors on Mac

As follow-up on this topic, I found that using this fix causes a mess of other problems, as it's creating the OpenGL context and etc. After fighting through a ton of issues and eventually getting stumped at a crash on compiling the embedded GLSL shaders, I realized that this probably isn't the intended use case :P
On that note, does anyone have an idea on how I can get around the original error or what I may be doing wrong?

Last edited by Hypernova^ (2017-06-10 13:51:16)


Board footer