Why do you need "include" files when using OpenGL

So I have been programming in c++ for a few months now and have just started in Game Development using OpenGL as my Graphics API. When I am setting up my project I understand why I need to add the library files to the project folder however I don't completely understand why I have to go into build properties and link the "include" folders of freeglut and GLTools in the "include" search path. Could someone give me an explanation for this?

Thanks!

Sounds like you're just asking what #include does for you. The short answer is that if your compiler has never been told about the existence of classes and functions, when it tries to compile your code, it will stop and complain that it has no idea what these classes and functions you're trying to use are. The library you link to gets used after compilation.

http://www.cplusplus.com/forum/articles/10627/





Last edited on
Remember, the #include directive causes the compiler to open another source file, usually referred to as a header file. The first place that it looks for that file is the directory (AKA file folder) where the current source code file is located. If it can not find it there, most compilers will begin to look through an optional list of directories to find it. The methods used to set this directory search list can vary from one compiler to another, but they generally involve either command line options or environment variables.

If you were to provide the full path to your header files, you would not need to add a search directory, but this would be tedious and it would make source code dependent on your current file system.

If you explore your IDE documentation, you might find an option to add particular directories to the search paths for all projects.

You have probably already experienced this, but go ahead and leave that step out. When you try to compile, you may notice that one of the very first error messages that you receive will say something along the lines of "can't find such and such a file."
Last edited on
Topic archived. No new replies allowed.