MinGW / OpenGL linking-problem

Sep 18, 2014 at 12:35pm
Hi there,

i'm currently lerning OpenGL-Programming with dev-cpp / MinGW-Compiler.

While working with a second renderpass using the result of the first pass as texture, it works fine with "glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, w, h, 0);", but always copying the pixel-data is very slow.
So i was looking for a way to render direct in memory and found the glFramebuffer-object should do what i want.

At this point i got problems with compiling.
For information: I don't really know how to setup the c-compiler. I always use presets and things like this.
At first i found out, i'm using glu.h, but the glFramebuffer-object is defined in glew.h. So i got compiler-errors concerning undefined glFramebuffers-funcions.
After downloading a MinGW-version of glew32.lib (libglew32.a), i put this in my lib-folder and added the concerning line to the linker-options. Also i put a glew.h-file in the include-folder and added:
1
2
3
#define GLEW_STATIC
#include <gl/glew.h>
#include <gl/glu.h> 
to my code.

This was the first time i manually added a library, and i'm quiet proud, that it worked so far, but the result is the following link-error:
g++.exe "Objects/MingW/clsCanvas.o" "Objects/MingW/clsSphere1.o" "Objects/MingW/frmOutput.o" "Objects/MingW/openGLProjectApp.o" "Objects/MingW/openGLProjectFrm.o" Objects/MingW/Projekt1_private.res -o "Output/MingW/Projekt1.exe" -L"C:/Program Files (x86)/Dev-Cpp/lib/wx/gcc_lib" -L"C:/Program Files (x86)/Dev-Cpp/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW32/lib" -mwindows -lwxmsw29u -lwxmsw29u_gl -lwxscintilla -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -luser32 -lopengl32 -lglut32 -lglu32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 "C:/Program Files (x86)/Dev-Cpp/MinGW32/lib/libglu32.a" "C:/Program Files (x86)/Dev-Cpp/MinGW32/lib/libglew32.a" "C:/Program Files (x86)/Dev-Cpp/MinGW32/lib/libglfw3.a"

C:/Program Files (x86)/Dev-Cpp/MinGW32/lib/libglew32.a(glew.o):glew.c:(.text+0x143ac): undefined reference to `glGetString@4'
C:/Program Files (x86)/Dev-Cpp/MinGW32/lib/libglew32.a(glew.o):glew.c:(.text+0x1666f): undefined reference to `glGetString@4'
C:/Program Files (x86)/Dev-Cpp/MinGW32/lib/libglew32.a(glew.o):glew.c:(.text+0x167be): undefined reference to `glGetString@4'
collect2: ld returned 1 exit status

mingw32-make.exe: *** [Output/MingW/Projekt1.exe] Error 1

Ausführung beendet
Compilation Failed. Make returned 2



Is there anyone who can help me in this point?

Thank you,

Frank
Last edited on Sep 18, 2014 at 1:05pm
Sep 18, 2014 at 2:49pm
The function "glGetString()" is exposed in the header file 'gl.h' which you forgot to include.
Sep 18, 2014 at 3:37pm
At first: thank you for replying.

I would be happy if you were right, but the includes were not complete in my post. The top of my cpp-file looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#define GLEW_STATIC
#include <gl/glew.h>
#include <gl/glu.h>
#include <gl/gl.h>
//#include <GL/glfw3.h>

//#include <gl/glext.h>
#include <math.h>

#include "clsCanvas.h"
#include "openGLProjectFrm.h" 


So i need another idea...

Last edited on Sep 18, 2014 at 3:39pm
Sep 18, 2014 at 5:39pm
closed account (10X9216C)
Computergeek01 wrote:
The function "glGetString()" is exposed in the header file 'gl.h' which you forgot to include.

Glew includes that and gives errors/warnings if you include it before glew. In any case forgetting to include a header doesn't cause linker errors.

Could try just putting glew.c into your project, it is only a single source file. Just to make sure it works.

Also, dev-cpp, eww.
Last edited on Sep 18, 2014 at 5:39pm
Sep 18, 2014 at 10:39pm
Order is okay. Already tried other order and got error-message not to inlude any glXXX.h before glew.h.

Found another downloadsource for glew (http://www.mediafire.com/download/20tlnt0eytt/glew-1.5.4-mingw32.zip). The achriv includes .c-files (about 10 files) also, but i don't really know how use them.
Using the libglew32.a and glew.h from this archiv, the error-message changed: the line C:/Program Files (x86)/Dev-Cpp/MinGW32/lib/libglew32.a(glew.o):glew.c:(.text+0x4397): undefined reference to `glGetString@4' appears now two times (and not three times as before).


What does this "Also, dev-cpp, eww." mean??

Last edited on Sep 19, 2014 at 8:11am
Sep 19, 2014 at 9:23am
Seems that i found a solution:

I did not use the "glGetString"-function myself. The function is called somewhere in the "glGenFramebuffers"-function, which leads to the undefied reference.

I tried to call "glGetString" myself to find out, if i get the same errormessage, but no errormessage appeard.
In fact - even more strange - after adding the "glGetString"-call to my code, also "glGenFramebuffers" was compiled without errors.

The code looks like this:
1
2
3
GLuint fbo = 0;
teststring = glGetString(1);
glGenFramebuffers(1, &fbo);


I know an effect (i think only concerning MinGW) which seems to be simelar somehow:
Sometimes classes produce undefined reference errors, when the destructor is implemented in the .h-file and therefore in the .c-file is no destructor-code.
If for example the .h-file contains:
~classname() {}

instead of:
~classname();

and in the .c-file:
classname::~classname() {}

So in MinGW for some reasons the linker-reference to the class is created when the destructor is implemented and without explizit implementation the linker misses the reference.
Somehow this seems to be the case with "glGetString" also.



PS. Now i have a problem with crashing exe-file, but for this i'ff open a new thread...
Topic archived. No new replies allowed.