MinGW-w64 linking problems

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 toWinMain’ /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

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.mkOn Mon, Aug 17, 2015 at 10:55 PM, Driedfruit wrote:

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 toWinMain’
/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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://www.caveproductions.org

2015-08-17 17:55 GMT-03:00, Driedfruit :

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.

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 < sik.the.hedgehog at gmail.com> wrote:

2015-08-17 17:55 GMT-03:00, Driedfruit :

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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://www.caveproductions.org

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:

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 toWinMain’ /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.

the wiki says : https://wiki.libsdl.org/SDL_PointInRect

but i get linker errors and indeed SDL_rect.h does not contain such function ?

Are you using SDL 2.0.4?

https://hg.libsdl.org/SDL/file/9f0a0c7de41a/include/SDL_rect.h

Jonny DOn Wed, Aug 19, 2015 at 8:24 AM, jeroen clarysse <jeroen.clarysse at telenet.be wrote:

the wiki says : https://wiki.libsdl.org/SDL_PointInRect

but i get linker errors and indeed SDL_rect.h does not contain such
function ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

apparently I?m using 2.0.0 which doesn?t have this function :-/

i?m not keen on upgrading to 2.0.4 since that means recompiling SDL_image, SDL_mixer, SDL_gfx, SDL_TTF and SDL_rtf :-)> Are you using SDL 2.0.4?

https://hg.libsdl.org/SDL/file/9f0a0c7de41a/include/SDL_rect.h

Jonny D

On Wed, Aug 19, 2015 at 8:24 AM, jeroen clarysse <@Jeroen_Clarysse> wrote:
the wiki says : https://wiki.libsdl.org/SDL_PointInRect

but i get linker errors and indeed SDL_rect.h does not contain such function ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

hello,
which error do you get?
and which compiler are you using?

???-??-?? ??:?? GMT+??:??, jeroen clarysse <jeroen.clarysse at telenet.be>:> apparently I?m using 2.0.0 which doesn?t have this function :-/

i?m not keen on upgrading to 2.0.4 since that means recompiling SDL_image,
SDL_mixer, SDL_gfx, SDL_TTF and SDL_rtf :slight_smile:

Are you using SDL 2.0.4?

https://hg.libsdl.org/SDL/file/9f0a0c7de41a/include/SDL_rect.h

Jonny D

On Wed, Aug 19, 2015 at 8:24 AM, jeroen clarysse <jeroen.clarysse at telenet.be> wrote:
the wiki says : https://wiki.libsdl.org/SDL_PointInRect

but i get linker errors and indeed SDL_rect.h does not contain such
function ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

it is fixed now : i manually added the code from 2.0.4 to 2.0.0. I will have to upgrade though since I don?t know what else is probably important> hello,

which error do you get?
and which compiler are you using?

???-??-?? ??:?? GMT+??:??, jeroen clarysse <@Jeroen_Clarysse>:

apparently I?m using 2.0.0 which doesn?t have this function :-/

i?m not keen on upgrading to 2.0.4 since that means recompiling SDL_image,
SDL_mixer, SDL_gfx, SDL_TTF and SDL_rtf :slight_smile:

Are you using SDL 2.0.4?

https://hg.libsdl.org/SDL/file/9f0a0c7de41a/include/SDL_rect.h

Jonny D

On Wed, Aug 19, 2015 at 8:24 AM, jeroen clarysse <@Jeroen_Clarysse> wrote:
the wiki says : https://wiki.libsdl.org/SDL_PointInRect

but i get linker errors and indeed SDL_rect.h does not contain such
function ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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.On Wed, 19 Aug 2015 12:53:31 +0200 Marcel Wysocki wrote:

On 08/17/2015 10:55 PM, Driedfruit wrote:

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 toWinMain’ /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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


driedfruit

Fwiw, 2.0.0 and 2.0.4 are ABI and API compatible, so you shouldn’t have
to recompile any of those libraries if you want to upgrade to get new
functions in 2.0.4.

(there are a LOT of fixes since 2.0.0…you are going to want to upgrade
sooner than later.)

–ryan.On 08/20/2015 03:44 AM, jeroen clarysse wrote:

apparently I?m using 2.0.0 which doesn?t have this function :-/

i?m not keen on upgrading to 2.0.4 since that means recompiling SDL_image, SDL_mixer, SDL_gfx, SDL_TTF and SDL_rtf :slight_smile: