问题
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!
回答1:
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
回答2:
USER DEFINED HEADERS SYNTAX IS #include "name of file.h " ....... there is no "<" or ">"....because that just asks the compiler to check in its directories were all headers are stored ...wereas " " ask compiler to check current directory....and of course make sure the header is defined in the same directory as ur main.c
来源:https://stackoverflow.com/questions/22377762/c-compile-error-no-such-file-or-directory-compilation-terminated