Sign in to follow this  
Dosser

OpenGL Linker errors in DevC++ (AARGH)

Recommended Posts

Dosser    122
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
Daaark    3553
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
Dosser    122
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
nPenAPaT    127
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
brandonman    102
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
hahaha    100
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
songho    268
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
Dosser    122
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
Dosser    122
I just installed the devpak that songho linked to, and it worked fine. The default programs work now, and if I use the 'glut' template (replacing the sample code with my own), my own programs work too.

Thanks :D

Share this post


Link to post
Share on other sites
itsdbest    134
Hey that works for me as well..

Thanks to dosser for raising this issue and thanks to songho for the link.

Feels good to have this working.... now off to some coding...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
  • Popular Now