PDA

View Full Version : OpenGL libraries linking



01-11-2005, 08:14 AM
Why should we link OpenGL libraries? I am using Visual C++ 6.0, I was told to inlcude OpenGL32.lib GLu32.lib glut32.lib into Project/Settings.

But, my program works fine even without including of those libraries. What happen? What is the different if I were to link the libraries and without linking it?

zukko
01-11-2005, 10:11 AM
maybe you are including them using #pragma comment(lib,"opengl32.lib"); or maybe you are not using the opengl functions

01-12-2005, 02:46 AM
I never include #pragma (I don't know what it is as well), and I am using pure OpenGL function, just really confuse.

I program OpenGL using Window Console Application, after I have compiled and build the file, I go to my Project Settings/Link, the libraries shown are:

kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

As you may see, the program works fine even without including any OpenGL libraries. Or may it be the case where the OpenGL libraries are included once, and need not to be included at the subsequent time?

I just want to know whether you all include those OpenGL libraries 'each time' you create a new project, or incluce it once, and no need to include it again next time when creating a new project? Or OpenGL libraries are not necessary for console application?

dvm
01-12-2005, 04:40 AM
Someone correct me if I'm wrong, but the libraries is what ties the executables with your source code. You're calling a library function, any function. The compiler will need the library file so it can find the address of the function in the dll file. My guess is that the compiler you're using knows where to find the .lib's
A couple of years ago when I started learning OpenGL this thing had me fumbled for 4 days, as I used an glaux function and my project could not link to the auxiliary library.
In the end, know that the thing happens, even if it is done automatically, and you don't know about it.
PS At least you know what to do if your compiler start spitting link errors :)

01-12-2005, 09:34 AM
I agree with you too. If any one who have better solution, just hope that you guys may share it here. I think my question is slightly out of OpenGL topic, however, as we are programming in OpenGL, we need to know some lower-end implementation especially for debugging purpose, right?

Meanwhile, I am looking for this answer too, if I manage to get the answer, and I will share it over here. ;)

zukko
01-12-2005, 10:49 AM
on your main() function write glLoadIdentity();
then compile and link, if it does it without any errors please tell me

01-12-2005, 12:06 PM
Is this what you mean:


void main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutCreateWindow("libLinking");
glutDisplayFunc(RenderScene);
glutReshapeFunc(Reshape);

glLoadIdentity();

setupRC();

glutMainLoop();
}If this is the code, then my IDE generate no error on it.

01-12-2005, 12:18 PM
I will not reply by today if I am buzy because I am rushing my OpenGL assignment and for another two hours more, it is the assignment deadline. :eek: What make ridiculous is that there is one last part remaining, that is I don't know how to transform a straight line to a curve line upon animation.

I know it is not fair to me ask for help for my assignment, but I just want to know is there any OpenGL API function which can transform straight line to a curve line? glTranslate? glScale? :confused:

For library linking issues, I hope that we can discuss further later. Now my time here is 05:14am :D

zukko
01-12-2005, 06:44 PM
1) you are using glut
2) i dont have the least idea why it doesnt have errors
3) for your assignment, use a line strip, then gradualy move on the X or Y axis the vertex points to start generating a curve

mikael_aronsson
01-13-2005, 12:47 AM
If you are allowed to use glu functions you could also create a spline/nurbs curve, then you can simply transform the line to a curve by moving the control handles for the curve.

Mikael

Bob
01-13-2005, 01:29 AM
GLUT automatically includes all necessary libraries. Open the glut.h header file and you will find a #pragma in there that includes opengl32.lib.

Try this code instead.

#include <GL/gl.h>

int main(int, char **)
{
glLoadIdentity();
}This one should not build correctly; the linker should complain about an unresolved external symbol.

Now add #include <GL/glut.h> before main, and see the linker error go away because it linkes the necessary libraries, allowing the linker to find the previously unresolved symbol name.

01-13-2005, 09:05 AM
Thanks everybody for the responses and suggestions given. However, before I can try on you all's suggestions, my assignment is already submitted, and just because of that curve line, I get 'D' for my assignment, how annoying and embarassing I am... :eek:

Even though my assignment has been passed up, but I still want to clear my doubt. What I am trying to do is to transform a horizontal straight line to a curve line, same as the shape for the smiling mouth when you type this " :) ". I remember there is one mathematic equation for this, is it y = ax^2 + bx + c? However, I will still keep on trying all the suggestions as suggested by you all, really appreciate, honestly.

Bob, you are right, glut automatically includes all the neccessary libraries, I have got errors when I try to compile using #include <GL/gl.h>

But there is another problem, I try to compile again with the #include <GL/gl.h>, but, this time I have included opengl32.lib glu32.lib glut32.lib manually, there are errors shown while I am expecting it to work fine seeming that I have already included those libraries manually.

And one more thing is that I am not so understand with the syntax such this, "**", where you have included "**" behind "char". Is it a C language? Because I am working with C++ and I have never seen this before.

dvm
01-13-2005, 09:36 AM
Bob provides again. Nice one, I never thought about glut. I thought that VC++ compiler had automated the proccess. How wrong I was.

If you're using glut function then ofcourse you have to include glut.h as well. Check what type of functions are giving you errors, gl, glu or glut.

Also for char **, yes it's a C feature. It's a pointer to a pointer and in this case a pointer to an array of pointers containing the command line arguments you called your program with. You've probably seen it before as char *argv[] which is equivalent.

01-13-2005, 11:05 AM
I see. Thanks ya moucard. Now I understand what "**" is. :cool: cool!