OpenGL / MinGW: undefined reference to 'glGetString' - solution

Mar 21, 2016 at 11:36pm
Hi All,

if you get linker-errors with MinGW concerning 'glGetStrig' or 'glGetSring@4' etc., inserting the followinng codeline somewhere in OpenGL initialisation might help:

 
const GLubyte* dummy = glGetString(1);

Note: 'glGetStrig' is also called by some library-functions. So this error may appear without any 'glGetStrig'-call in your own code.


Greetz,
FG.
Last edited on Mar 21, 2016 at 11:39pm
Mar 22, 2016 at 8:10am
Linker error cannot be solved by a function call. You need to provide the correct libraries to the linker. Why do you think that could help?
Mar 22, 2016 at 10:01am
Hi coder777,

you're right, this is absolutly strange, but for me it was even more strange, that a library-function which is not called by my program-code, causes linking-problems. For me this meaned that there is something wrong with the inner dependencies of the library.
In fact this is why i found this 'solution': I alway got 'glGetString'-linking-errors at a code where i was sure that it shold work and somehow i figured out, that a call of 'glGenFramebuffer' or 'glBindFramebuffer' causes them. This was so strange, that i wanted to find out, what happens if i call 'glGetString' directly. And - uups - suddenly also the 'gl...Framebuffer'-call was compiled correctly.

I don't know why, but i had this problem in two programs now and both times it worked.

Maybe it has to do something with compiler-heuristics, like this: in some cases with MinGW an object, need an expicit destructor in the .c file to be linkable. A destructor-function in the object-protoype (something like "~Name() {..};") leads to 'undefined reference to'-errors. With any other function (incuding the constructor) this causes no problem. So obviously the compiler needs the destuctor as 'hook' for the linking-table-entry. This might be some simelar thing...

Regards,
F
Last edited on Mar 22, 2016 at 10:04am
Mar 22, 2016 at 11:37am
It sounds like as if you provide multiple conflicting [version] librarys. When you add that particular line the linker accidentally chooses the right one. If so this behavior might even change the next time you change your code.
Mar 22, 2016 at 12:49pm
There you migth be right. I'm not good in setting up c-compilers and the result is more accidetially then planned. But this is the second independent compiler-setup, where this appers. So i obviously installed accidentially two tlimes the same incompatible librarys.

In fact - which is quiet funny - yesterday i had this problem and it was my own forgotton post from 2014 (http://www.cplusplus.com/forum/general/142808/) i found on google, which helped me this time.
So i thought, it will be good to make a second post for other people.

By the way: also if libraries don't fit, this behaviour is quiet strange, isn't it??
Topic archived. No new replies allowed.