Jump to content
  • Advertisement
Sign in to follow this  
Bombshell93

[SOLVED] MinGW, Glut, Glew problems

This topic is 1348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi,
I'm trying to get started with OpenGL in C++ but I'm having constant issues with it, for IDE I have chosen Eclipse with MinGW as my tool chain.
while using MinGW and GLUT works fine I want to make use of the greater functionality OpenGL offers such as VBO's, Shader Programs, etc. all signs seem to point to Glew being the best option and some sources claiming it my only option but for the life of me I keep running into errors,

at the moment this is how the console reports,
I am using a minGW built library, but I've also tried the dll as a library and the pre-built libraries from the glew sourceforge

18:15:36 **** Incremental Build of configuration Debug for project Sample ****
Info: Internal Builder is used for build
g++ -static-libgcc -static-libstdc++ -o Sample.exe main.o -lopengl32 -lglu32 -lfreeglut -lglew32 
main.o: In function `ZN4MeshC2Ev':
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:4: undefined reference to `__glewGenBuffers'
main.o: In function `ZN4MeshD2Ev':
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:11: undefined reference to `__glewDeleteBuffers'
main.o: In function `ZN4Mesh4FillEP6VertexPjjjj':
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:29: undefined reference to `__glewBindBuffer'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:31: undefined reference to `__glewBufferData'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:32: undefined reference to `__glewBindBuffer'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:34: undefined reference to `__glewBufferData'
main.o: In function `ZN4Mesh4DrawEv':
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:37: undefined reference to `__glewBindBuffer'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:38: undefined reference to `__glewBindBuffer'
main.o: In function `main':
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:62: undefined reference to `glewInit@0'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:65: undefined reference to `glewGetErrorString@4'
C:\Users\Bombshell\EclipseCpp\TTEngine\Sample\Debug/../main.cpp:67: undefined reference to `glewGetString@4'
collect2.exe: error: ld returned 1 exit status

18:15:36 Build Finished (took 127ms)

and here are the files

[spoiler]
header.h

#ifndef SAMPLE_HEADER_H
#define SAMPLE_HEADER_H

#include <GL/glew.h>
#include <GL/glut.h>
#include <stdio.h>
#include <windows.h>

struct Vertex {
public:
	float px, py, pz;
	Vertex() {
		px = py = pz = 0;
	}

	Vertex(float pX, float pY, float pZ) {
		px = pX;
		py = pY;
		pz = pZ;
	}
};

class Mesh {
private:
	unsigned int* bufferObjects;
	Vertex* vertexData;
	unsigned int* indexData;
	unsigned int vertexCount;
	unsigned int indexCount;
public:
	Mesh();
	~Mesh();
	void Fill(Vertex* vertices, unsigned int* indices, unsigned int vertCount,
			unsigned int indCount, GLenum usage);
	void Draw();
};

#endif /* HEADER_H_ */

main.cpp

#include "header.h"

Mesh::Mesh() {
	glGenBuffers(2, bufferObjects);
	vertexData = 0;
	indexData = 0;
	vertexCount = 0;
	indexCount = 0;
}
Mesh::~Mesh() {
	glDeleteBuffers(2, bufferObjects);
	delete bufferObjects;
	bufferObjects = 0;
	delete vertexData;
	vertexData = 0;
	delete indexData;
	indexData = 0;
}
void Mesh::Fill(Vertex* vertices, unsigned int* indices, unsigned int vertCount,
		unsigned int indCount, GLenum usage) {
	if (vertexData != 0)
		delete vertexData;
	vertexData = vertices;
	if (indexData != 0)
		delete indexData;
	indexData = indices;
	vertexCount = vertCount;
	indexCount = indCount;
	glBindBuffer(GL_ARRAY_BUFFER, bufferObjects[0]);
	glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * vertexCount, vertexData,
			usage);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjects[1]);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indexCount,
			indexData, usage);
}
void Mesh::Draw() {
	glBindBuffer(GL_ARRAY_BUFFER, bufferObjects[0]);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjects[1]);
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(Vertex), ((void*) 0));
	glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, ((void*) 0));
	glDisableClientState(GL_VERTEX_ARRAY);
}
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.5f, -0.5f);
glVertex2f(0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();

glFlush();
}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutCreateWindow("OpenGL Setup Test");
GLenum err = glewInit();
if (GLEW_OK != err) {
	/* Problem: glewInit failed, something is seriously wrong. */
	fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
}
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

[/spoiler]
as far as C++ goes I'm fairly new, I've used it in the past for basic DirectX projects, like a model viewer but not extensively and not with any issues like this which weren't already heavily documented.
I've tried google all I can but I just can't seem to get around it,
Any and all help would be greatly appricieted,
Thanks for reading,
Bombshell

Share this post


Link to post
Share on other sites
Advertisement

I'm not sure about MinGW but MSVC will silently ignore libraries targeting the wrong platform (x64 vs x86). Are you certain both compiler and downloaded library actually match?

Share this post


Link to post
Share on other sites

well I've now tried every lib and dll file available from the glew pre-compile's (x84 and x64)
the only things giving me a different error (which btw is also the error I have not got any links to glew libraries)
is Win32/glew32s.lib

21:10:10 **** Incremental Build of configuration Debug for project Sample ****
Info: Internal Builder is used for build
g++ -static-libgcc -static-libstdc++ "-LC:\\MinGW\\lib\\Release\\win32" -o Sample.exe main.o -lopengl32 -lglu32 -lfreeglut -lglew32s 
Warning: corrupt .drectve at end of def file
C:\MinGW\lib\Release\win32/glew32s.lib(tmp/glew_static/Release/Win32/glew.obj):(.text$mn+0x7): undefined reference to `_imp__wglGetProcAddress@4'
C:\MinGW\lib\Release\win32/glew32s.lib(tmp/glew_static/Release/Win32/glew.obj):(.text$mn+0x4): undefined reference to `_imp__wglGetProcAddress@4'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\MinGW\lib\Release\win32/glew32s.lib(tmp/glew_static/Release/Win32/glew.obj): bad reloc address 0x4 in section `.text$mn'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

and the dlls with x64/glew32.dll saying it is an unknown file type and stopping immediately or
Win32/glew32.dll

21:10:10 **** Incremental Build of configuration Debug for project Sample ****
Info: Internal Builder is used for build
g++ -static-libgcc -static-libstdc++ "-LC:\\MinGW\\lib\\Release\\win32" -o Sample.exe main.o -lopengl32 -lglu32 -lfreeglut -lglew32s 
Warning: corrupt .drectve at end of def file
C:\MinGW\lib\Release\win32/glew32s.lib(tmp/glew_static/Release/Win32/glew.obj):(.text$mn+0x7): undefined reference to `_imp__wglGetProcAddress@4'
C:\MinGW\lib\Release\win32/glew32s.lib(tmp/glew_static/Release/Win32/glew.obj):(.text$mn+0x4): undefined reference to `_imp__wglGetProcAddress@4'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\MinGW\lib\Release\win32/glew32s.lib(tmp/glew_static/Release/Win32/glew.obj): bad reloc address 0x4 in section `.text$mn'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

Share this post


Link to post
Share on other sites

Shouldn't glew be linked before OpenGL and the rest? I.e. rearrange the link order so glew comes first. I'm not sure it will make a difference, but try it anyway

Share this post


Link to post
Share on other sites

If you link the static version of GLEW (that is, glew32s.lib), you need to define GLEW_STATIC before including the header.

 

Also, I'm not sure about the prebuilt libraries with MinGW. Oftentimes projects will only supply prebuilt MSVC binaries for Windows. Personally I just build libraries (like GLEW) myself to avoid any such problems. It should be trivial for GLEW, especially if your MinGW comes with msys.

Share this post


Link to post
Share on other sites

I've opened msys and I have the source for glew but I've not used command line builders before (at least not without an IDE between me and them), google isn't helping as each page I find is assuming the reader has used other such tools before, I haven't a clue what I'm doing to be honest.

EDIT:
sorted thanks for the help guys,
For those unaware or in need of the help,
Using MSYS:

open msys and type
cd "Path to Makefile"
make
a lot easier than I was making it
 

Edited by bombshell93

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!