How to fix this Error: #include <gl/glut.h> "Cannot open source file gl/glut.h"

150,672

Solution 1

You probably haven't installed GLUT:

  1. Install GLUT If you do not have GLUT installed on your machine you can download it from: http://www.xmission.com/~nate/glut/glut-3.7.6-bin.zip (or whatever version) GLUT Libraries and header files are • glut32.lib • glut.h

Source: http://cacs.usc.edu/education/cs596/OGL_Setup.pdf

EDIT:

The quickest way is to download the latest header, and compiled DLLs for it, place it in your system32 folder or reference it in your project. Version 3.7 (latest as of this post) is here: http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip

Folder references:

glut.h: 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\GL\'
glut32.lib: 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\'
glut32.dll: 'C:\Windows\System32\'

For 64-bit machines, you will want to do this.
glut32.dll: 'C:\Windows\SysWOW64\'

Same pattern applies to freeglut and GLEW files with the header files in the GL folder, lib in the lib folder, and dll in the System32 (and SysWOW64) folder.
1. Under Visual C++, select Empty Project.
2. Go to Project -> Properties. Select Linker -> Input then add the following to the Additional Dependencies field:
opengl32.lib
glu32.lib
glut32.lib

Reprinted from here

Solution 2

If you are using Visual Studio Community 2015 and trying to Install GLUT you should place the header file glut.h in C:\Program Files (x86)\Windows Kits\8.1\Include\um\gl

Solution 3

Visual Studio Community 2017

Go here : C:\Program Files (x86)\Windows Kits\10

and do whatever you were supposed to go in the given directory for VS 13.

in the lib folder, you will find some versions, I copied the 32-bit glut.lib files in amd and x86 and 64-bit glut.lib in arm64 and x64 directories in um folder for every version that I could find.

That worked for me.

EDIT : I tried this in windows 10, maybe you need to go to C:\Program Files (x86)\Windows Kits\8.1 folder for windows 8/8.1.

Share:
150,672

Related videos on Youtube

Jay
Author by

Jay

Updated on January 12, 2020

Comments

  • Jay
    Jay over 4 years

    I was doing some OpenGL programming in C++.

    This is part of my code:

    #include <time.h>
    #include <windows.h>
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glut.h> <<< Error here "Cannot open source file gl/glut.h"
    

    How can I fix this?

    EDIT: I am using Microsoft Visual C++ Express Edition. Sorry forgot to mention it

    • Jesus Ramos
      Jesus Ramos about 12 years
      You need to install GLUT if I'm not mistaken it isn't included by default in Windows OpenGL
    • Jay
      Jay about 12 years
      @JesusRamos How can I install that?
    • wkl
      wkl about 12 years
    • Jay
      Jay about 12 years
      Is it possible to provide instructions for the installation process or a link? cheers
  • Jay
    Jay about 12 years
    Are there any instructions for Microsoft Visual C++ Express Edition
  • Dominic Tancredi
    Dominic Tancredi about 12 years
    Updated my post to hopefully give you better instructions re-printed from another site.
  • Roy T.
    Roy T. about 10 years
    Old but: its not necessary to contaminate the System32 or SysWOW64 folders this way. Just place the header and library files in a folder anywhere on your hard drive and add the folder to the Include Directory and Library Directory of the project. Here is a nice tutorial with some pictures on how to do this: blogs.msdn.com/b/vsproject/archive/2009/07/07/…