Sign in to follow this  
pheserus

Strange Mingw Linker Problem

Recommended Posts

Hello people of gamedev.net, this is my first post here, and its about a strange issue I've been having with the i586-mingw32msvc compiler.
I'm using Xubuntu and I'm trying to compile a win32 application that uses SDL and OpenGL. It compiles properly, but I'm having trouble linking
the SDL and OpenGL libraries "-lmingw32 -lSDLmain -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf -lopengl32 -lglu32". I don't think it is properly locating the libraries
because it gives me tons of undefined reference errors.

[quote]undefined reference to `_Mix_PlayMusic'
undefined reference to `_glLoadIdentity@0'
undefined reference to `_glTranslatef@12'
undefined reference to `_SDL_GetTicks'
undefined reference to `_TTF_RenderText_Blended'
And many more...
[/quote]

When I compile it for linux (g++) it works properly. But not for Windows (i586-mingw32msvc-g++). I don't know what else to do to set up mingw.
I have installed the windows version of the SDL libraries into /usr/i586-mingw32msvc/lib and tried using the -L option to specify a linker search path.
But to no avail.If anyone has any clue to what I should do, I would greatly appreciate it if you would share your wisdom. If you need any other
details, just let me know.

Share this post


Link to post
Share on other sites
Typically with gcc, you have to specify the libraries in a particular order. For example, since glu32 has references to stuff in opengl32, opengl32 needs to appear after glu32 on the linker command line. You'll may have to reorder your SDL libraries too. This is because the linker only makes a single pass through the libraries when looking-up symbols (in order to reduce memory usage?).

Alternatively, you can try putting "-Wl,--start-group" and "-Wl,--end-group" before and after your libraries on the linker command line. I'm not sure if you can do that through the gcc/g++ frontends, but ld certainly has those --start-group and --end-group flags

Share this post


Link to post
Share on other sites
Just to clarify, are you cross compiling a win32 binary from linux?

Some pointers:

Have you tried using the gcc and specifying all the paths (-I and -L) as well as all the libs (-l) yourself, just to be sure he grabs the right ones?
If you rename one of the win32 libs whose functions can't be found, do you get an error that the lib could not be found?

It is also interesting, that the OpenGL functions are c++ name mangled. This should not be the case, since the API is pure C! There should be some #ifdef __cplusplus extern "C" { #endif in the OpenGL headers to prevent this.

Are you linking the right object files? Are you using the win32 compiler to create those object files?

Share this post


Link to post
Share on other sites
[quote name='Ohforf sake' timestamp='1307280505' post='4819738']
It is also interesting, that the OpenGL functions are c++ name mangled.
[/quote]
I'm not sure they are. It is my understanding that the '@12' and '@0' suffixes are an artifact of the stdcall calling convention, though I'm not 100% on this. MinGW's OpenGL headers do contain the __cplusplus preprocessor checks.

Share this post


Link to post
Share on other sites
[quote name='edd²' timestamp='1307279849' post='4819734']
Typically with gcc, you have to specify the libraries in a particular order. For example, since glu32 has references to stuff in opengl32, opengl32 needs to appear after glu32 on the linker command line. You'll may have to reorder your SDL libraries too. This is because the linker only makes a single pass through the libraries when looking-up symbols (in order to reduce memory usage?).

Alternatively, you can try putting "-Wl,--start-group" and "-Wl,--end-group" before and after your libraries on the linker command line. I'm not sure if you can do that through the gcc/g++ frontends, but ld certainly has those --start-group and --end-group flags
[/quote]
I tried re-ordering the OpenGL libraries but it made no difference, and I don't know how to properly order the others.



[quote name='Ohforf sake' timestamp='1307280505' post='4819738']
Just to clarify, are you cross compiling a win32 binary from linux?

Some pointers:

Have you tried using the gcc and specifying all the paths (-I and -L) as well as all the libs (-l) yourself, just to be sure he grabs the right ones?
If you rename one of the win32 libs whose functions can't be found, do you get an error that the lib could not be found?

It is also interesting, that the OpenGL functions are c++ name mangled. This should not be the case, since the API is pure C! There should be some #ifdef __cplusplus extern "C" { #endif in the OpenGL headers to prevent this.

Are you linking the right object files? Are you using the win32 compiler to create those object files?
[/quote]
I renamed libopengl32.a and it gave me this. Which is even more puzzling than before.
[quote]/usr/lib/gcc/i586-mingw32msvc/4.4.4/../../../../i586-mingw32msvc/bin/ld: cannot find -lopengl32[/quote]

I am cross compiling win32 from linux. I never seemed to have this problem cross compiling until now.
All files were compiled with i586-mingw32msvc-g++, and yes I have used both -l and -L to specifiy the files and paths.

Thanks for both of your help by the way.

Share this post


Link to post
Share on other sites
[quote name='Pheserus' timestamp='1307281684' post='4819742']
I tried re-ordering the OpenGL libraries but it made no difference, and I don't know how to properly order the others.
[/quote]
No difference [i]at all[/i]? Did you get [i]exactly the same output[/i] as before?

The solution to this is to use the mushy stuff between your ears; take note of each symbol that the linker says it can't find. Figure out which library or object file is using that symbol and which library defines it. Make sure the library that defines it comes after all objects/libraries that call said symbol on the linker command line.

This will have to be done not only with the OpenGL libs, but with SDL too. It's really not that hard and this 'skill' will be useful many times over in future.

[quote]
I renamed libopengl32.a and it gave me this. Which is even more puzzling than before.
[quote]/usr/lib/gcc/i586-mingw32msvc/4.4.4/../../../../i586-mingw32msvc/bin/ld: cannot find -lopengl32[/quote]
[/quote]
Renamed it to what!? You really don't want to go round renaming system libraries. It is named correctly.

Perhaps it would help if you gave the entire linker output and command line.

Share this post


Link to post
Share on other sites
[quote]
Renamed it to what!? You really don't want to go round renaming system libraries. It is named correctly.

Perhaps it would help if you gave the entire linker output and command line.
[/quote]
I named it from libopengl32.a to libopengl. I only renamed it to test out what Ohforf said, then changed it back.
Anyways I decided to try cross compiling with CodeBlocks instead of in a terminal and now it works.
It gave me the same linker errors in CodeBlocks until I went to Project>Build Options>Linker Settings,
and added each of the SDL libraries with the exact file path under Link Libraries.

I'm glad I found a method that works, though I might revisit this issue to sort it out one day.
Thanks for all the help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this