I am trying to compile a OpenGL program which uses SDL for context creation and image loading. When I compile it on Linux natively, it compiles and runs without error. I have installed MXE in /opt/mxe and have checked that the SDL2 directory (which contains headers) is in /opt/mxe/usr/i686-w64-mingw32.static/include/
while the corresponding libraries (libSDL.a
, etc.) are in /opt/mxe/usr/i686-w64-mingw32.static/lib/
.
The included header files are <SDL2/SDL.h>
and <SDL2/SDL_image.h>
I am trying to compile the said program using
i686-w64-mingw32.static-gcc 5_transformation.c -I/opt/mxe/usr/i686-w64-mingw32.static/include -L/opt/mxe/usr/i686-w64-mingw32.static/lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lGLEW -lopengl32 -lm -mwindows
However, it gives multiple undefined reference errors: [http://pastebin.com/JaadTNnv
]1
Many of these errors seem related to Direct3D and such, which I am not using (but SDL2 might, internally). Do I have to link against them too? Am I even doing this right? (MXE page doesn't seems to have any detailed instructions).
PS. This question, or it's variants, seem to be pretty popular across internet. However, I have already followed their instructions. My main function is defined as int main(int argc, char *argv[])
, I am linking against -lmingw32, -lSDL2main and -mwindows, I have made sure that the path in GCC's arguments are correct, I tried putting i686-w64-mingw32.static-sdl-config --cflags --libs
and i686-w64-mingw32.static-pkg-config SDL_image --cflags --libs
in arguments instead of explicit linking (that simply gave undefined reference for SDL functions like SDL_GL_CreateContext
and IMG_Load
and said that Package SDL_image was not found in the pkg-config search path.
).