The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
MinGW-w64 linking problems
Driedfruit
Guest

Hi list!

I faintly remember someone here being quite experienced with new
mingw. Even if not maybe we can figure it out together.

I'm trying to use the MinGW-w64 to build an SDL2 program, the host
machine is actually Windows 64-bit, the target arch is
x86_64 and the environment is MSYS2.

The error I'm getting is:

g++ [my .o files] /mingw64/lib/libSDL2main.a -L/mingw64/lib -lSDL2main
-lSDL2 -lSDL2_image -lSDL2_mixer -lglew32 -lglu32 -lopengl32 -lOpenAL32
-o game

/usr/lib/gcc/x86_64-pc-msys/4.9.2/../../../../lib/libmsys-2.0.a(libcmain.o):
In function
`main': /scripts2/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:39:
undefined reference to
`WinMain' /scripts2/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7f):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`WinMain' collect2: error: ld returned 1 exit status

As you can see, I *do* have -lSDL2main, I also tried feeding it the .a
file directly, and I played around with -l order (this used to help
with mingw32 builds). My program does have a "int main(int argc, char
*argv)", with 'extern "C"'.

Few words about MSYS2: the environment comes with it's own package
manager (pacman), with libraries for both 32 and 64 bit development.
Among the libraries are both SDL and SDL2 with all the helper libs (and
they even have SDL_gfx), so that's what I'm using: the prebuilt MSYS2
SDL2 libraries. SDL2 is at 2.0.3, BTW.

I suspected their build was missing the WinMain, but no,
"nm /mingw64/lib/libSDL2main.a" reveals the "WinMain" symbol.

I would appreciate *any hints* at all, thank you.

--
driedfruit
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
MinGW-w64 linking problems
M. Gerhardy
Guest

These two files might help you to find the missing parts.

https://github.com/mxe/mxe/blob/master/src/sdl2-1.patch
https://github.com/mxe/mxe/blob/master/src/sdl2.mk


On Mon, Aug 17, 2015 at 10:55 PM, Driedfruit wrote:
Quote:
Hi list!

I faintly remember someone here being quite experienced with new
mingw. Even if not maybe we can figure it out together.

I'm trying to use the MinGW-w64 to build an SDL2 program, the host
machine is actually Windows 64-bit, the target arch is
x86_64 and the environment is MSYS2.

The error I'm getting is:

g++ [my .o files] /mingw64/lib/libSDL2main.a -L/mingw64/lib -lSDL2main
-lSDL2 -lSDL2_image -lSDL2_mixer -lglew32 -lglu32 -lopengl32 -lOpenAL32
-o game

/usr/lib/gcc/x86_64-pc-msys/4.9.2/../../../../lib/libmsys-2.0.a(libcmain.o):
In function
`main': /scripts2/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:39:
undefined reference to
`WinMain' /scripts2/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7f):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`WinMain' collect2: error: ld returned 1 exit status

As you can see, I *do* have -lSDL2main, I also tried feeding it the .a
file directly, and I played around with -l order (this used to help
with mingw32 builds). My program does have a "int main(int argc, char
*argv)", with 'extern "C"'.

Few words about MSYS2: the environment comes with it's own package
manager (pacman), with libraries for both 32 and 64 bit development.
Among the libraries are both SDL and SDL2 with all the helper libs (and
they even have SDL_gfx), so that's what I'm using: the prebuilt MSYS2
SDL2 libraries. SDL2 is at 2.0.3, BTW.

I suspected their build was missing the WinMain, but no,
"nm /mingw64/lib/libSDL2main.a" reveals the "WinMain" symbol.

I would appreciate *any hints* at all, thank you.

--
driedfruit
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



--
http://www.caveproductions.org
MinGW-w64 linking problems
Sik


Joined: 26 Nov 2011
Posts: 905
2015-08-17 17:55 GMT-03:00, Driedfruit:
Quote:
As you can see, I *do* have -lSDL2main, I also tried feeding it the .a
file directly, and I played around with -l order (this used to help
with mingw32 builds). My program does have a "int main(int argc, char
*argv)", with 'extern "C"'.

Make sure the main function is in a file including SDL2/SDL.h and do
*not* try to declare main yourself (i.e. no prototypes, just write the
function itself - SDL already has the prototype). What happens is that
the header file has a macro that replaces main with SDL_main, and the
real main (or WinMain or whatever) resides within the library.

That said, I *never* got it to work on MinGW, honestly... (or better
said, I forget the exact details every time) I find it easier to just
undefine main and not include SDL2main so the real main is used. MinGW
can use main on GUI programs (unlike Visual Studio), so it's not a
problem there.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
MinGW-w64 linking problems
M. Gerhardy
Guest

Usually you should not include SDL2/SDL.h but only SDL.h and use pkg-config or sdl-config or set up your include paths.


But using mxe (the links I posted above) makes it super easy to cross compile with mingw32/mingw64 for static and dynamically linked applications.

On Tue, Aug 18, 2015 at 4:42 PM, Sik the hedgehog wrote:
Quote:
2015-08-17 17:55 GMT-03:00, Driedfruit:
Quote:
As you can see, I *do* have -lSDL2main, I also tried feeding it the .a
file directly, and I played around with -l order (this used to help
with mingw32 builds). My program does have a "int main(int argc, char
*argv)", with 'extern "C"'.

Make sure the main function is in a file including SDL2/SDL.h and do
*not* try to declare main yourself (i.e. no prototypes, just write the
function itself - SDL already has the prototype). What happens is that
the header file has a macro that replaces main with SDL_main, and the
real main (or WinMain or whatever) resides within the library.

That said, I *never* got it to work on MinGW, honestly... (or better
said, I forget the exact details every time) I find it easier to just
undefine main and not include SDL2main so the real main is used. MinGW
can use main on GUI programs (unlike Visual Studio), so it's not a
problem there.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





--
http://www.caveproductions.org
MinGW-w64 linking problems
Marcel Wysocki
Guest

Looks like youre using the wrong gcc (x86_64-pc-msys)
Should be something like x86_64-w64-mingw32 instead.

The x86_64-pc-msys is one used to compile msys components.
You dont want to compile the msys runtime into your app.


On 08/17/2015 10:55 PM, Driedfruit wrote:
Quote:
Hi list!

I faintly remember someone here being quite experienced with new
mingw. Even if not maybe we can figure it out together.

I'm trying to use the MinGW-w64 to build an SDL2 program, the host
machine is actually Windows 64-bit, the target arch is
x86_64 and the environment is MSYS2.

The error I'm getting is:

g++ [my .o files] /mingw64/lib/libSDL2main.a -L/mingw64/lib -lSDL2main
-lSDL2 -lSDL2_image -lSDL2_mixer -lglew32 -lglu32 -lopengl32 -lOpenAL32
-o game

/usr/lib/gcc/x86_64-pc-msys/4.9.2/../../../../lib/libmsys-2.0.a(libcmain.o):
In function
`main': /scripts2/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:39:
undefined reference to
`WinMain' /scripts2/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7f):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`WinMain' collect2: error: ld returned 1 exit status

As you can see, I *do* have -lSDL2main, I also tried feeding it the .a
file directly, and I played around with -l order (this used to help
with mingw32 builds). My program does have a "int main(int argc, char
*argv)", with 'extern "C"'.

Few words about MSYS2: the environment comes with it's own package
manager (pacman), with libraries for both 32 and 64 bit development.
Among the libraries are both SDL and SDL2 with all the helper libs (and
they even have SDL_gfx), so that's what I'm using: the prebuilt MSYS2
SDL2 libraries. SDL2 is at 2.0.3, BTW.

I suspected their build was missing the WinMain, but no,
"nm /mingw64/lib/libSDL2main.a" reveals the "WinMain" symbol.

I would appreciate *any hints* at all, thank you.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
MinGW-w64 linking problems
Driedfruit
Guest

On Wed, 19 Aug 2015 12:53:31 +0200
Marcel Wysocki wrote:

Quote:
Looks like youre using the wrong gcc (x86_64-pc-msys)
Should be something like x86_64-w64-mingw32 instead.

The x86_64-pc-msys is one used to compile msys components.
You dont want to compile the msys runtime into your app.


That was it. I feel incredibly stupid. After installing the appropriate
gcc package, everything went on smoothly. Thank you!

So, for everyone's consideration: msys2 is a very easy to get
up-and-running (unless you're being stupid like me) environment to
produce windows builds of your SDL-base code, both 32 and 64 bit. It
includes all the required libraries in it's repositories.

Some notes: make sure your MINGW32 environment "which gcc" reports
"/mingw32/bin/gcc" and your MINGW64 environment "which gcc" reports
"/mingw64/bin/gcc". If either reports "/bin/gcc", you're using the msys
compiler (the mistake I made). Same goes for /include and /lib dirs,
obviously.

`sdl2-config --libs` is not usable as is as. It adds "-lmingw32" which
is not needed. Strip it, or provide your own ld flags. Something to look
into on the SDL side.

M. Gerhardy, Sik, thank you for your advice too, I did double check the
"main" definitions, and I did read through those makefiles. Ultimately
the problem was in the enviornment, but it's good stuff to keep in mind.

Quote:

On 08/17/2015 10:55 PM, Driedfruit wrote:
Quote:
Hi list!

I faintly remember someone here being quite experienced with new
mingw. Even if not maybe we can figure it out together.

I'm trying to use the MinGW-w64 to build an SDL2 program, the host
machine is actually Windows 64-bit, the target arch is
x86_64 and the environment is MSYS2.

The error I'm getting is:

g++ [my .o files] /mingw64/lib/libSDL2main.a -L/mingw64/lib
-lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lglew32 -lglu32
-lopengl32 -lOpenAL32 -o game

/usr/lib/gcc/x86_64-pc-msys/4.9.2/../../../../lib/libmsys-2.0.a(libcmain.o):
In function
`main': /scripts2/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:39:
undefined reference to
`WinMain' /scripts2/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7f):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`WinMain' collect2: error: ld returned 1 exit status

As you can see, I *do* have -lSDL2main, I also tried feeding it
the .a file directly, and I played around with -l order (this used
to help with mingw32 builds). My program does have a "int main(int
argc, char *argv)", with 'extern "C"'.

Few words about MSYS2: the environment comes with it's own package
manager (pacman), with libraries for both 32 and 64 bit development.
Among the libraries are both SDL and SDL2 with all the helper libs
(and they even have SDL_gfx), so that's what I'm using: the
prebuilt MSYS2 SDL2 libraries. SDL2 is at 2.0.3, BTW.

I suspected their build was missing the WinMain, but no,
"nm /mingw64/lib/libSDL2main.a" reveals the "WinMain" symbol.

I would appreciate *any hints* at all, thank you.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



--
driedfruit
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org