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
Comments
-
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 about 10 yearsHave you installed the
glut
development package? IsGLUT/glut.h
in the compilers default include search path? -
Don't You Worry Child about 10 yearsTry specifying path to the directory having the header file using
-I
option. -
Mauren about 10 yearsHeader names are case-sensitive if you're under *nix systems.
-
Ayohaych about 10 years@Mauren I'm running Windows 8. Followed what it says on the site and no luck
-
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 about 10 years@Mauren MinGW is a Windows compiler.
-
Ayohaych about 10 years@Lundin Yeah so what am I doing wrong?
-
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 about 10 yearsTry adding the path to directory having shared library files using
-L
option.
-
-
Ayohaych about 10 yearsI 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 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 about 10 years@AndyOHart See e.g. here for how to find out the default include search path.
-
Ayohaych about 10 years@Okay thanks. It gave me this error on compile: c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lGL
-
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 about 10 yearsHow do I do that using Mingw? Grep didn't seem to be recognized?
-
Some programmer dude about 10 years@AndyOHart Skip the pipe and the
grep
part, it just means you will get some unrelated data. -
Ayohaych about 10 years
-
Ayohaych about 10 yearsgot 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/bin/ 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/mingw32/4.8.1/;c:/ming w/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/
-
msrd0 over 9 yearsI 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