Discussion:
Compiling SDL2 Application on Windows 7 32bit + MinGW/Msys
Alex Barry
2012-08-11 17:12:05 UTC
Permalink
Hello ladies and gents,

Just as a note, I've came across this issue before and was able to resolve
it by using Visual Studio (rather than mingw), but I don't know that this
should be necessary.

I've written an SDL2 based library, and created a make file:

CC=mingw32-g++
CFLAGS=-O2 -Wall `sdl2-config --cflags` -I./include
LDFLAGS=`sdl2-config --libs` -lSDL2_ttf -lopengl32 -lglu32
OTHERFLAGS=-static
SOURCES=application.cpp event.cpp exceptions.cpp thread.cpp window.cpp
EXECUTABLE=sdlui
$(CC) $(OTHERFLAGS) $(CFLAGS) $(LDFLAGS) $(SOURCES) -o $(EXECUTABLE)
rm -f $(EXECUTABLE)
clean: clean-executable
rebuild: clean all
The output I get, however, is quite bad:

$ mingw32-make -f Makefile.win32
mingw32-g++ -static -O2 -Wall `sdl2-config --cflags` -I./include
`sdl2-config --libs` -lSDL2_ttf -lopengl32 -lglu32 application.cpp event.cp
p exceptions.cpp thread.cpp window.cpp -o sdlui
C:/MinGW/msys/1.0/local/lib\libSDL2main.a(SDL_windows_main.o): In function
undefined reference to `SDL_main'
undefined reference to `SDL_PollEvent'
undefined reference to `SDL_PollEvent'
undefined reference to `SDL_Init'
undefined reference to `barrysoft::FontFactory::getInstance()'
undefined reference to `barrysoft::FontFactory::getInstance()'
undefined reference to `barrysoft::FontFactory::~FontFactory()'
undefined reference to `SDL_Quit'
undefined reference to `SDL_GetError'
undefined reference to `SDL_GetError'
undefined reference to `SDL_mutexP'
undefined reference to `SDL_CreateMutex'
undefined reference to `SDL_mutexP'
undefined reference to `SDL_mutexV'
undefined reference to `SDL_mutexP'
undefined reference to `SDL_mutexV'
undefined reference to `SDL_Delay'
undefined reference to `SDL_mutexV'
undefined reference to `SDL_mutexP'
undefined reference to `SDL_mutexV'
undefined reference to `SDL_mutexP'
undefined reference to `SDL_WaitThread'
undefined reference to `SDL_DestroyMutex'
undefined reference to `SDL_CreateMutex'
undefined reference to `SDL_CreateThread'
undefined reference to `SDL_mutexV'
undefined reference to `SDL_DestroyMutex'
undefined reference to `SDL_mutexP'
undefined reference to `SDL_mutexV'
undefined reference to `SDL_mutexV'
undefined reference to `SDL_CreateWindow'
undefined reference to `SDL_SetWindowSize'
undefined reference to `SDL_SetWindowPosition'
undefined reference to `SDL_GL_DeleteContext'
undefined reference to `SDL_GL_MakeCurrent'
undefined reference to `SDL_GL_CreateContext'
undefined reference to `SDL_GL_SetSwapInterval'
undefined reference to `SDL_GL_SetAttribute'
undefined reference to `SDL_GL_SetAttribute'
undefined reference to `SDL_GL_SetAttribute'
undefined reference to `SDL_GL_SetAttribute'
undefined reference to `SDL_GL_SetAttribute'
more undefined references to `SDL_GL_SetAttribute' follow
undefined reference to `SDL_GetWindowPosition'
undefined reference to `SDL_DestroyWindow'
undefined reference to `SDL_GetWindowID'
undefined reference to `SDL_ShowWindow'
undefined reference to `SDL_HideWindow'
undefined reference to `SDL_GetWindowPosition'
undefined reference to `SDL_GetWindowID'
collect2: ld returned 1 exit status
mingw32-make: *** [all] Error 1
So, first thing I thought was the sdl2-config was giving bad output, so I
$ sdl2-config --libs --cflags
-L/usr/local/lib -lmingw32 -lSDL2main -lSDL2 -mwindows
-I/usr/local/include/SDL2 -Dmain=SDL_main
The directories and libraries are all correct.

So, now I'm down to a few options. Either I broke my mingw/msys config
(which is possible), or SDL2 broke mingw32 builds.

Anyone else with experience with the latest SDL2 from hg (just pulled this
morning) and mingw32? If anyone else has built it, then I'll try
re-installing mingw32 to see if that fixes it.

Thanks,
-Alex
Gabriel Jacobo
2012-08-11 17:20:50 UTC
Permalink
Post by Alex Barry
$ mingw32-make -f Makefile.win32
mingw32-g++ -static -O2 -Wall `sdl2-config --cflags` -I./include
`sdl2-config --libs` -lSDL2_ttf -lopengl32 -lglu32 application.cpp event.cp
p exceptions.cpp thread.cpp window.cpp -o sdlui
C:/MinGW/msys/1.0/local/lib\libSDL2main.a(SDL_windows_main.o): In
undefined reference to `SDL_main'
Can you try running mingw32-g++ -static -O2 -Wall `sdl2-config --cflags`
-I./include -lSDL2_ttf -lopengl32 -lglu32 application.cpp event.cpp
exceptions.cpp thread.cpp window.cpp -o sdlui `sdl2-config --libs`

That is with the SDL2 libraries at the end of the command line, if you
updated MingW32 recently it's possible they've switched GCC versions and
the dependency solving "feature/bug" is causing those unresolved symbols.
--
Gabriel.
Alex Barry
2012-08-11 17:45:55 UTC
Permalink
That gives me a bunch of different errors, but it does link to SDL:

$ mingw32-make -f Makefile.win32
mingw32-g++ -static -O2 -Wall `sdl2-config --cflags` -I./include
-lSDL2_ttf -lopengl32 -lglu32 application.cpp event.cpp exceptions.cpp thre
ad.cpp window.cpp `sdl2-config --libs`
undefined reference to `barrysoft::FontFactory::getInstance()'
undefined reference to `barrysoft::FontFactory::getInstance()'
undefined reference to `barrysoft::FontFactory::~FontFactory()'
C:/MinGW/msys/1.0/local/lib\libSDL2main.a(SDL_windows_main.o): In function
undefined reference to `SDL_main'
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_systimer.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_systimer.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_dxjoystick.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_winmm.o): In function
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:185: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:190: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:197: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:197: undefined
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_winmm.o): In function
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:144: undefined
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_winmm.o): In function
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:55: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:55: undefined
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_winmm.o): In function
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:54: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:54: undefined
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_winmm.o): In function
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:228: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:231: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:241: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:244: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:320: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:378: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:378: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:324: undefined
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_winmm.o): In function
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:115: undefined
c:\Users\Alexander\SDL\x86/../src/audio/winmm/SDL_winmm.c:115: undefined
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_syshaptic.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windows.o): In function
c:\Users\Alexander\SDL\x86/../src/core/windows/SDL_windows.c:47: undefined
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windows.o): In function
c:\Users\Alexander\SDL\x86/../src/core/windows/SDL_windows.c:61: undefined
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
undefined reference to `IID_IUnknown'
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
undefined reference to `IID_IUnknown'
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
C:/MinGW/msys/1.0/local/lib\libSDL2.a(SDL_windowskeyboard.o): In function
collect2: ld returned 1 exit status
mingw32-make: *** [all] Error 1
Not sure how to fix this either, but we're moving in the right direction :)
-Alex
Post by Alex Barry
$ mingw32-make -f Makefile.win32
mingw32-g++ -static -O2 -Wall `sdl2-config --cflags` -I./include
`sdl2-config --libs` -lSDL2_ttf -lopengl32 -lglu32 application.cpp event.cp
p exceptions.cpp thread.cpp window.cpp -o sdlui
C:/MinGW/msys/1.0/local/lib\libSDL2main.a(SDL_windows_main.o): In
undefined reference to `SDL_main'
Can you try running mingw32-g++ -static -O2 -Wall `sdl2-config --cflags`
-I./include -lSDL2_ttf -lopengl32 -lglu32 application.cpp event.cpp
exceptions.cpp thread.cpp window.cpp -o sdlui `sdl2-config --libs`
That is with the SDL2 libraries at the end of the command line, if you
updated MingW32 recently it's possible they've switched GCC versions and
the dependency solving "feature/bug" is causing those unresolved symbols.
--
Gabriel.
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Gabriel Jacobo
2012-08-11 19:42:08 UTC
Permalink
Post by Alex Barry
$ mingw32-make -f Makefile.win32
mingw32-g++ -static -O2 -Wall `sdl2-config --cflags` -I./include
-lSDL2_ttf -lopengl32 -lglu32 application.cpp event.cpp exceptions.cpp thre
ad.cpp window.cpp `sdl2-config --libs`
mingw32-make: *** [all] Error 1
Not sure how to fix this either, but we're moving in the right direction :)
-Alex
The solution is to start rearranging your command so libraries that depend
on others appear first (in a left to right order) in the command line...

So, as SDL2_ttf depends on SDL2, you'd put it first. After SDL2 you'd put
opengl32 because SDL2 will be using it,etc. It may be even possible you'll
need to list a library twice.
--
Gabriel.
Alex Barry
2012-08-16 20:26:11 UTC
Permalink
Just a note to other people who come across this thread, what I ended up
doing was reverting to an older version of gcc and g++ by doing the
following in the msys shell:

$ mingw-get install gcc-v3-core
$ mingw-get install gcc-v3-c++

Note: This will change the default gcc version on your system - if you want
to return to gcc 4.x (I think the names may change in the eventual future
of gcc 5.x), do:
$ mingw-get install gcc-core
$ mingw-get install gcc-c++

Then, I was originally trying to build a static library, which was still
giving me issues in gcc 3.x, so I tried building with -shared rather than
-static, and everything built fine.

Gabriel, thanks for the troubleshooting - I've been doing a lot of windows
development for work lately and haven't touched gcc in a while. I'm sort
of surprised at how messed up the linker is in gcc 4.5.x, but maybe that's
intentional in some sense? I don't know, but anyway, thanks for the help!

Hope that helps someone else down the road, too,
-Alex
Post by Gabriel Jacobo
Post by Alex Barry
$ mingw32-make -f Makefile.win32
mingw32-g++ -static -O2 -Wall `sdl2-config --cflags` -I./include
-lSDL2_ttf -lopengl32 -lglu32 application.cpp event.cpp exceptions.cpp thre
ad.cpp window.cpp `sdl2-config --libs`
mingw32-make: *** [all] Error 1
Not sure how to fix this either, but we're moving in the right direction :)
-Alex
The solution is to start rearranging your command so libraries that depend
on others appear first (in a left to right order) in the command line...
So, as SDL2_ttf depends on SDL2, you'd put it first. After SDL2 you'd put
opengl32 because SDL2 will be using it,etc. It may be even possible you'll
need to list a library twice.
--
Gabriel.
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Loading...