user1956185
user1956185

Reputation: 389

Setting up OpenGL in CodeBlocks

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.

Upvotes: 4

Views: 19339

Answers (2)

Aradhika Acharya
Aradhika Acharya

Reputation: 21

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.

Upvotes: 2

ssell
ssell

Reputation: 6597

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:

enter image description here

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:

enter image description here

This is the folder that contains the gl subdirectory.

Upvotes: 2

Related Questions