Jump to content
  • Advertisement
Sign in to follow this  
Dosser

OpenGL Linker errors in DevC++ (AARGH)

This topic is 4021 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

Hey all, Trying to get into GL coding, but keep failing miserably. I am currently following the "OpenGL Programming Guide" book, copying tutorials into DevCpp and trying them out. However, they just don't work. Here is the code I've tried #include <GL/glut.h> void display (void) { glColor3f(1.0, 1.0, 1.0); glBegin(GL_POLYGON); glVertex3f(0.25, 0.25, 0.0); glVertex3f(0.75, 0.25, 0.0); glVertex3f(0.75, 0.75, 0.0); glVertex3f(0.25, 0.75, 0.0); glEnd(); glFlush(); } void init (void) { glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); } int main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(250,250); glutInitWindowPosition(100,100); glutCreateWindow("Example 1-2: a white square"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; } And I'm linking with: -lopengl32 -lglu32 I get linker errors. Here is my compile log: Compiler: Default compiler Building Makefile: "D:\Programming\RED BOOK EXAMPLES\1-2 white square\Makefile.win" Executing make clean rm -f square.o Project1.exe gcc.exe -c square.c -o square.o -I"D:/Dev-Cpp/include" gcc.exe square.o -o "Project1.exe" -L"D:/Dev-Cpp/lib" -lopengl32 -lglu32 square.o(.text+0x1c):square.c: undefined reference to `__glutInitWithExit' square.o(.text+0x37):square.c: undefined reference to `__glutCreateWindowWithExit' square.o(.text+0x52):square.c: undefined reference to `__glutCreateMenuWithExit' square.o(.text+0x79):square.c: undefined reference to `_imp__glColor3f' square.o(.text+0x87):square.c: undefined reference to `_imp__glBegin' square.o(.text+0xa8):square.c: undefined reference to `_imp__glVertex3f' square.o(.text+0xc9):square.c: undefined reference to `_imp__glVertex3f' square.o(.text+0xea):square.c: undefined reference to `_imp__glVertex3f' square.o(.text+0x10b):square.c: undefined reference to `_imp__glVertex3f' square.o(.text+0x112):square.c: undefined reference to `_imp__glEnd' square.o(.text+0x119):square.c: undefined reference to `_imp__glFlush' square.o(.text+0x14b):square.c: undefined reference to `_imp__glClearColor' square.o(.text+0x159):square.c: undefined reference to `_imp__glMatrixMode' square.o(.text+0x160):square.c: undefined reference to `_imp__glLoadIdentity' square.o(.text+0x18e):square.c: undefined reference to `_imp__glOrtho' square.o(.text+0x1da):square.c: undefined reference to `glutInitDisplayMode' square.o(.text+0x1ee):square.c: undefined reference to `glutInitWindowSize' square.o(.text+0x202):square.c: undefined reference to `glutInitWindowPosition' square.o(.text+0x21f):square.c: undefined reference to `glutDisplayFunc' square.o(.text+0x224):square.c: undefined reference to `glutMainLoop' collect2: ld returned 1 exit status make.exe: *** [Project1.exe] Error 1 Execution terminated Can someone please help? I'm sure the problem isn't too complicated, I just can't fix it.

Share this post


Link to post
Share on other sites
Advertisement
glu and glut are 2 different libraries. You need GLUT too. Never used it, so I don't know where you get it.

Also, DevC++ is an old, abandonned IDE. I suggest you download the free MSVC++ 2005 express edition, or you run MinGW under Code::Blocks instead of DevC++.

Share this post


Link to post
Share on other sites
Sorry about that, have edited my lnker options a few times, forgot glut this time. However, still 21 errors


Compiler: Default compiler
Building Makefile: "D:\Programming\RED BOOK EXAMPLES\1-2 white square\Makefile.win"
Executing make clean
rm -f square.o Project1.exe

gcc.exe -c square.c -o square.o -I"D:/Dev-Cpp/include"

gcc.exe square.o -o "Project1.exe" -L"D:/Dev-Cpp/lib" -lopengl32 -lglu32 -lglut32

square.o(.text+0x1c):square.c: undefined reference to `__glutInitWithExit'
square.o(.text+0x37):square.c: undefined reference to `__glutCreateWindowWithExit'
square.o(.text+0x52):square.c: undefined reference to `__glutCreateMenuWithExit'

square.o(.text+0x79):square.c: undefined reference to `_imp__glColor3f'
square.o(.text+0x87):square.c: undefined reference to `_imp__glBegin'

square.o(.text+0xa8):square.c: undefined reference to `_imp__glVertex3f'
square.o(.text+0xc9):square.c: undefined reference to `_imp__glVertex3f'
square.o(.text+0xea):square.c: undefined reference to `_imp__glVertex3f'
square.o(.text+0x10b):square.c: undefined reference to `_imp__glVertex3f'
square.o(.text+0x112):square.c: undefined reference to `_imp__glEnd'
square.o(.text+0x119):square.c: undefined reference to `_imp__glFlush'
square.o(.text+0x14b):square.c: undefined reference to `_imp__glClearColor'
square.o(.text+0x159):square.c: undefined reference to `_imp__glMatrixMode'
square.o(.text+0x160):square.c: undefined reference to `_imp__glLoadIdentity'
square.o(.text+0x18e):square.c: undefined reference to `_imp__glOrtho'
square.o(.text+0x1da):square.c: undefined reference to `glutInitDisplayMode'

square.o(.text+0x1ee):square.c: undefined reference to `glutInitWindowSize'
square.o(.text+0x202):square.c: undefined reference to `glutInitWindowPosition'
square.o(.text+0x21f):square.c: undefined reference to `glutDisplayFunc'
square.o(.text+0x224):square.c: undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status

make.exe: *** [Project1.exe] Error 1

Execution terminated

Share this post


Link to post
Share on other sites
It seem you have your libraries so the only thing that is not present is the
#include <gl\gl.h> and if glut.h is in the "gl" directory also then you should change it to #include <gl\glut.h>

Share this post


Link to post
Share on other sites
These are what I use for includes: windows.h, gl\gl.h, gl\glu.h, and gl\glaux.h. My linker looks like this: -lopengl32 -lglu32 -lglaux -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32. I never get any linker errors or include errors with this. Don't ask me what all is in the library:P I forgot, but found them in google. BTW, i'm using Dev C++ too.

Share this post


Link to post
Share on other sites
Click on the project menu and go to project options. Find the box with the heading linker.

add this to it:
-lopengl32
-lglut (or -lglut32 cant remember)

that should do it:)

Share this post


Link to post
Share on other sites
Dosser,
The easiest way to start OpenGL applications with Dev-C++ is using the project template. When you install Dev-C++, an OpenGL project template comes with it. When you install GLUT package(pak), a GLUT project template is automatically added into Dev-C++.

The project template configures all settings for me, for example, linking required libraries. I only need to replace my source codes into the project. It is very convenient to me to create new OpenGL application right away with Dev-C++.

Try the GLUT project template first and compile the sample code. If there is no error, then, everything is ready to go. If there are errors (link or compile errors) then, you can tell the setting of Dev-C++ is broken.

Here is instructions if you don't know where is glut project template;
File >> New >> Project...
"New project..." window is pop up, then select:
Multimedia tab
you will see glut and OpenGL project template icons.

By the way, the link option for GLUT app should be like this:
-lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32

Share this post


Link to post
Share on other sites
I'm starting to think there's a problem with my GLUT

I've been trying out the template programs, and can get the standard "openGL" program to work (using windows to open the window, respond to key press etc.). I don't have an option for a glut program, but do have 'freeglut' option. This doesn't link properly. Here are the errors from the default freeglut program.

Compiler: Default compiler
Building Makefile: "D:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "D:\Dev-Cpp\Makefile.win" all
gcc.exe -c main9.c -o main9.o -I"D:/Dev-Cpp/include" -DFREEGLUT_STATIC

gcc.exe main9.o -o "Project4.exe" -L"D:/Dev-Cpp/lib" -mwindows -lfreeglut -lglu32 -lopengl32 -lwinmm -lgdi32

Warning: resolving __imp__glViewport by linking to __imp__glViewport@16
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Warning: resolving __imp__glMatrixMode by linking to __imp__glMatrixMode@4
Warning: resolving __imp__glLoadIdentity by linking to __imp__glLoadIdentity@0
Warning: resolving __imp__glPushMatrix by linking to __imp__glPushMatrix@0
Warning: resolving __imp__glPopMatrix by linking to __imp__glPopMatrix@0
main9.o(.text+0x1c):main9.c: undefined reference to `__glutInitWithExit'
main9.o(.text+0x37):main9.c: undefined reference to `__glutCreateWindowWithExit'
main9.o(.text+0x52):main9.c: undefined reference to `__glutCreateMenuWithExit'
main9.o(.text+0xdc):main9.c: undefined reference to `_imp__glFrustum'
main9.o(.text+0x134):main9.c: undefined reference to `_imp__glClear'
main9.o(.text+0x14c):main9.c: undefined reference to `_imp__glColor3d'
main9.o(.text+0x177):main9.c: undefined reference to `_imp__glTranslated'
main9.o(.text+0x199):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x1b8):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x202):main9.c: undefined reference to `_imp__glTranslated'
main9.o(.text+0x224):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x243):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x297):main9.c: undefined reference to `_imp__glTranslated'
main9.o(.text+0x2b9):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x2d8):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x334):main9.c: undefined reference to `_imp__glTranslated'
main9.o(.text+0x356):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x375):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x3bf):main9.c: undefined reference to `_imp__glTranslated'
main9.o(.text+0x3e1):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x400):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x454):main9.c: undefined reference to `_imp__glTranslated'
main9.o(.text+0x476):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x495):main9.c: undefined reference to `_imp__glRotated'
main9.o(.text+0x624):main9.c: undefined reference to `_imp__glClearColor'
main9.o(.text+0x632):main9.c: undefined reference to `_imp__glEnable'
main9.o(.text+0x640):main9.c: undefined reference to `_imp__glCullFace'
main9.o(.text+0x64e):main9.c: undefined reference to `_imp__glEnable'
main9.o(.text+0x65c):main9.c: undefined reference to `_imp__glDepthFunc'
main9.o(.text+0x66a):main9.c: undefined reference to `_imp__glEnable'
main9.o(.text+0x678):main9.c: undefined reference to `_imp__glEnable'
main9.o(.text+0x686):main9.c: undefined reference to `_imp__glEnable'
main9.o(.text+0x694):main9.c: undefined reference to `_imp__glEnable'

main9.o(.text+0x6b2):main9.c: undefined reference to `_imp__glLightfv'
main9.o(.text+0x6d0):main9.c: undefined reference to `_imp__glLightfv'

main9.o(.text+0x6ee):main9.c: undefined reference to `_imp__glLightfv'
main9.o(.text+0x70c):main9.c: undefined reference to `_imp__glLightfv'

main9.o(.text+0x72a):main9.c: undefined reference to `_imp__glMaterialfv'
main9.o(.text+0x748):main9.c: undefined reference to `_imp__glMaterialfv'
main9.o(.text+0x766):main9.c: undefined reference to `_imp__glMaterialfv'
main9.o(.text+0x784):main9.c: undefined reference to `_imp__glMaterialfv'
collect2: ld returned 1 exit status

make.exe: *** [Project4.exe] Error 1

Execution terminated


Should I just give up on DevCpp and try again with MSVC, or will I get the same problems there too?

Share this post


Link to post
Share on other sites
Hmm, i have the same with issue with Glut. I installed the dev-pak and the default example program does not linker correct.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!