user969416
user969416

Reputation:

Undefined references using GLUT

I have been using SDL with success to learn OpenGL, however I am following tutorials that are using GLUT and I attempted to switch over to GLUT because it looks easier to use for novices and I feel I would pick the content up quicker. I thought this would be a simple quick and painless process, however I am running into the following problem when attempting to compile GLUT content (using MinGW) (I've downloaded GLUT and extracted the header file to my includes so it is being included correctly, and I have also extracted the lib files to the lib folder and I'm linking against it, the .DLL for glut is present in my system32 so it is being called successfully.

I'm clueless as to what I am doing wrong and would be grateful for any help and suggestions

Build messages when compiling the following small piece of content (which won't do anything at the moment but should compile):

#include <stdlib.h>
#include <GL/glut.h>

static int day = 0, year = 0;

void init()

{

glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);

}

void display(void)

{

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);

glPushMatrix();
glutWireSphere(1.0,20,16);
glRotatef((GLfloat) year, 0.0,1.0,0.0);
glTranslatef(2.0,0.0,0.0);
glRotatef((GLfloat) day, 0.0, 1.0, 0.0);
glutWireSphere(0.2,10,8);
glPopMatrix();
glutSwapBuffers();

}

//void reshape(int w, int h)

int main(int argc, char **argv)

{



}

Builder Errors:

C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to    `__glutInitWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `__glutCreateWindowWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `__glutCreateMenuWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glClearColor'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glShadeModel'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glClear'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glColor3f'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glPushMatrix'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutWireSphere'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glRotatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glTranslatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glRotatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutWireSphere'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glPopMatrix'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutSwapBuffers'|
||=== Build finished: 15 errors, 0 warnings ===|

Upvotes: 1

Views: 12402

Answers (2)

kchoi
kchoi

Reputation: 525

Yes, I had to include this piece of code to get it to work on windows.

#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif

It seems linker on windows links through windows.h to access the .dll files in System32

Upvotes: 3

Tam&#225;s Szelei
Tam&#225;s Szelei

Reputation: 23921

No, you aren't linking against glut (nor gl for that matter). Or it is a bad version, but I doubt that. You can try posting your project configuration or Makefile. The _imp__gl* things are libGL, and glut* things are glut, obviously. Also, make sure that you are linking against a library format that your linker understands. *.lib files are typically MS-COFF format, which is Microsoft's own flavor of the COFF standard. The linker in mingw (ld) won't be able to link this file. You need a static library with the .a extension (typically).

Upvotes: 0

Related Questions