C Compile Error (No such file or directory, compilation terminated)

23,867

First of all you need to check that there is a glut.h file, in a GLUT folder.

Then you tell the compiler where to find it using the -I command-line option (note, it's capital i, not 1 or l):

$ gcc -I/path/to/folder opengl.c -o opengl -lGL -lGLU -lglut

In the command above, replace /path/to/folder to the folder where the GLUT folder is.

You might also need to tell the linker where the libraries are, which is done with the -L option:

$ gcc -I/path/to/folder opengl.c -o opengl -L/path/to/libs -lGL -lGLU -lglut
Share:
23,867
Ayohaych
Author by

Ayohaych

I suck at programming

Updated on September 09, 2020

Comments

  • Ayohaych
    Ayohaych over 3 years

    I'm on Windows trying to learn some OpenGL. I Installed mingw and have a test file. I put my test.c file in a glut folder, which contains glut files such as the glut32.dll and library file. I used mingw in cmd to run the file using this:

    gcc opengl.c -o opengl -lGL -lGLU -lglut
    

    And I got this error:

    opengl.c:1:23 fatal error: GLUT/glut.h: No such file or directory
    #include <GLUT/glut.h>
    

    compilation terminated.

    Not sure what I'm doing wrong, anybody know? Thanks!

    • Some programmer dude
      Some programmer dude about 10 years
      Have you installed the glut development package? Is GLUT/glut.h in the compilers default include search path?
    • Don't You Worry Child
      Don't You Worry Child about 10 years
      Try specifying path to the directory having the header file using -I option.
    • Mauren
      Mauren about 10 years
      Header names are case-sensitive if you're under *nix systems.
    • Ayohaych
      Ayohaych about 10 years
      @Mauren I'm running Windows 8. Followed what it says on the site and no luck
    • Ayohaych
      Ayohaych about 10 years
      @JoachimPileborg could you elaborate on how I do this? I'm running Windows 8 and I'm not sure what to do. I have downloaded GLUT 3.7, not sure what to do with it all though. And how do I add glut.h to default search path, thanks
    • Lundin
      Lundin about 10 years
      @Mauren MinGW is a Windows compiler.
    • Ayohaych
      Ayohaych about 10 years
      @Lundin Yeah so what am I doing wrong?
    • Ayohaych
      Ayohaych about 10 years
      @MadHatter I did that and the error went away but now it's saying it cant find the libraries
    • Don't You Worry Child
      Don't You Worry Child about 10 years
      Try adding the path to directory having shared library files using -L option.
  • Ayohaych
    Ayohaych about 10 years
    I removed the GL/ and I used include "glut.h" instead of <> and it worked but gave me a load of errors about missing libraries. The .c file is inside the glut folder so I thought it would work. Do I have to specify the -I path and -L path every time I run it or can I set them up ? Also, I tried it just there. I did the -L but it says it can't find any of those extra elements like -lGl and all
  • Some programmer dude
    Some programmer dude about 10 years
    @AndyOHartIf you don't copy the headers/libraries to anywhere the compiler looks at by default, you will have to add those flags.
  • Some programmer dude
    Some programmer dude about 10 years
    @AndyOHart See e.g. here for how to find out the default include search path.
  • Ayohaych
    Ayohaych about 10 years
    @Okay thanks. It gave me this error on compile: c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bi‌​n/ld.exe: cannot find -lGL
  • Some programmer dude
    Some programmer dude about 10 years
    @AndyOHart To find out the default search path for libraries, run the command gcc -print-search-dirs | grep libraries
  • Ayohaych
    Ayohaych about 10 years
    How do I do that using Mingw? Grep didn't seem to be recognized?
  • Some programmer dude
    Some programmer dude about 10 years
    @AndyOHart Skip the pipe and the grep part, it just means you will get some unrelated data.
  • Ayohaych
    Ayohaych about 10 years
  • Ayohaych
    Ayohaych about 10 years
    got this when I did it install: c:\mingw\bin\../lib/gcc/mingw32/4.8.1/ programs: =c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/;c:/mingw/bin/../‌​libexec/gc c/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32‌​/bin/mingw32/4.8.1/; c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bi‌​n/ libraries: =c:/mingw/bin/../lib/gcc/mingw32/4.8.1/;c:/mingw/bin/../lib/‌​gcc/;c:/m ingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/mi‌​ngw32/4.8.1/;c:/ming w/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;c:/m‌​ingw/bin/../lib/gcc/
  • msrd0
    msrd0 over 9 years
    I don't think that <GLUT/glut.h> was a user-defied header, and btw all common compilers (like gcc) check for the header file in the current directory if it could not be found elsewhere