Setting up OpenGL in CodeBlocks
Solution 1
The issue is that you are telling Code::Blocks to look for opengl32.lib
, glu32.lib
, etc. but not where to look for them. Hence the error during linkage.
Under Project Build Options
-> Search Directories
-> Linker
you need to add the directories containing your OpenGL libraries. Example:
Note that the directory containing your OpenGL libraries will probably be different from mine, since according to the link in your question they should be wherever you put MinGW.
You will also need to make sure you add to the Search Directories
the location of the OpenGL header files. Example:
This is the folder that contains the gl
subdirectory.
Solution 2
After downloading the GLUT bin zip file (considering you already installed codeblocks earlier), you extract all the files in it and copy those three files separately. The glut32.lib goes to c:\program files\mingw\lib and copy glut32.dll to c:\windows\system and copy glut.h (header file) to c:\program files\mingw\include\GL
Then open codeblocks and go for new project>GLUT. Then set up the GLUT location to Mingw(in program files) and then finish. It worked for me just fine.
user1956185
Updated on June 09, 2022Comments
-
user1956185 almost 2 years
I am having trouble getting the right setings in order to use OpenGl in CodeBlocks.
I have used the instructions from this tutorial: GLUT but for my project to run I need the following flags: -lGL -lGLU -lglut which I can set in the Other linker options tab from Build options. When I do this, the compiler says
cannot find -lGL -lGLU -lglut
. What do I have to install in order for these libraries to work? GL.h GLU.h glut.h? and if yes how can I link them to the project? By adding them in the Link libraries tab? And also from the project tree which appears in Build options does the name of the project have to be selected when I install these libraries, or Debug or Release?In Build options, if I select the name of the project, at Link libraries I have the following: glut32, opengl32, glu32, winmm, gdi32 but I don't remember giving a path for them. Are they correct or do I have to change them as well?
I would like to mention that the created project is a GLUT project and that I am using Windows 7.
-
user1956185 almost 10 yearsI added the directories as you said and I still get the error. If I have these flags in the Other linker options
-lGL -lGLU -lglut
it says that they cannot be found, and if I erase them, I get an error with undefined reference to several functions. -
David G almost 10 years@user1956190 Do you have the dlls in
Mingw/bin
and in yoursystem32
folder? -
user1956185 almost 10 yearsYes. I had them in
system32
and I copied them also inMingw/bin
and it still doesn't work. I haveglu32.dll
andglut32.dll
. Do I need more? If yes, which ones? -
David G almost 10 years@user1956190 Instead of
lGL -lGLU
, try doing-lglu32 -lglut32
. -
user1956185 almost 10 yearsWell it finds the files, but I get the undefined references errors. Also I forgot to mention that I have Windows 7 on 64-bits. Should I have copied the dlls in SysWOW64 as well?
-
David G almost 10 years@user1956190 I wouldn't know as I have 32-bit but try that as well. What result do you get?
-
user1956185 almost 10 yearsWith
-lglu32 -lglut32
I get undefined references to some functions and if I try with-lGL -lGLU -lglut
it doesn't find the files. Actually what I am trying to do is to run this program from this website Game because I encountered the same errors and the solution was to link-lGL -lGLU -lglut
. But in my case that doesn't work either. -
user1956185 almost 10 yearsLet us continue this discussion in chat.