Why must OpenGL projects be built? (CMake, premake, etc)

Hi,

As you might have already guessed I’m completely new to OpenGL, and graphics programming in general, and I have what might seem like a stupid question:

Why do you have to build a workspace/project using tools like premake, CMake etc, in order to use OpenGL?
A lot of tutorials says that you have to, but I have yet to find one that can give a good explanation as of why.

And as an extension to that question, I wonder: Wouldn’t it be sufficient to simply put all header files, code files, link libraries, and so on, in the appropriate folders and directories,
and simply supply the compiler with the appropriate flags and search paths?

I fail to understand why one cannot simply compile OpenGL applications like any other C/C++ application, are OpenGL applications, or any other graphics application for that matter, so different?

You only have to link opengl32 to compile your project.
Probably you are using program that are designed to be compiled on multiple platform. In this case CMake generate the project for your platform.
Use project configuration is a good habit and it’s a must on linux platform where every distribution have different development environment.

I fail to understand why one cannot simply compile OpenGL applications like any other C/C++ application, are OpenGL applications, or any other graphics application for that matter, so different?

The purpose of, for example, a tutorial is to get someone up and running quickly. The fastest way to do that is to give them code that comes with a working build system. And since everyone has their own build systems, the most effective way to provide a working build system is to use a build system that works with any other build system.

See, you seem to like just compiling from the command-line. That’s great… for you. Most other programmers, especially new ones. do not. They want some GUI application that they can just run. They want a ready-made makefile that they can download and make. And so forth.

They don’t want to have to be told, “This tutorial requires these dependencies, so download them all, compile them, include their headers in your compiling command line, then include their libraries in your linking command line, etc.” So we provide them with a safe, simple, and effective alternative that is easy to use and works all the time.

Personally, even if you’re comfortable compiling stuff from a command-line, you really should use some form of build system. If you make anything larger than a few files, it really helps.

And as an extension to that question, I wonder: Wouldn’t it be sufficient to simply put all header files, code files, link libraries, and so on, in the appropriate folders and directories,
and simply supply the compiler with the appropriate flags and search paths?

No. There is no “the compiler”. There are many compilers, used by many different people. Windows has Visual Studio and GCC by way of MingW. These use two completely different command-lines. Things are more standardized on Linux, where Clang and GCC use the same options.

And how would you “supply the compiler with the appropriate flags and search paths?” Even if you pick a compiler, the most this would be would be a batch/script file of some sort. That’s a very difficult thing to write and maintain. And considering that there are very good build systems out there that turn what would be long, complex build scripts into what may be 30-lines of easily maintainable code… I see no reason why someone would even want to do that.

Thanks for the two answers.

Alfonse, I can see how this makes sense for the purpose of making an universal tutorial, that it makes it incredibly much easier to accommodate for the many different setups the ones following the tutorial might have.

However if I were to build my own application, independent of a tutorial that is, would it be necessary to use third-party utilities like CMake and premake then?
As I in that case would build an .exe file, with my compiler, that would at the very least be able to run under the same platform it was developed on, be it windows, OSX, or one of the particular linux-distributions.

I guess my question could be rephrased to wether this would be a necessity when you are developing something yourself, and not following the prewritten code provided by a tutorial.

I’m currently using Code::Blocks as an IDE, and I don’t know how this works for other IDEs, but in Code::Blocks it’s quite simple to configure your own compiler, provided you have some knowlegde about the API and your compiler, to handle APIs like OpenMP, OpenGL and so on when building the .exe.

Thanks for the answers.

Alphonse, I do of course see that tools like CMake and premake make good sense to use for a tutorial in order to accomodate for the many different setups people following the tutorial might have.

However, maybe I should rephrase my question into wether this is a necessity when developing something yourself, and not simply copy-pasting code from a tutorial?

However, maybe I should rephrase my question into wether this is a necessity when developing something yourself, and not simply copy-pasting code from a tutorial?

Of course not. You can use whatever build tools you want. So long as you know how use them and which libraries you need to link with.

Ok, thanks for helping me get some clarity on this subject.:slight_smile:

Since I’m new to Graphics programming I did get a little confused when every online tutorial said you have to use tools like CMake and premake, as I have never really needed any third-party tools for plain C/C++ programming.
I think tutorials should mention that it isn’t a necessity for the purpose of graphics programming itself, when it isn’t.

Since I’m new to Graphics programming I did get a little confused when every online tutorial said you have to use tools like CMake and premake

My confusion is that I have neither seen nor written any tutorial that says you have to use such things. They will generally talk about them, because as previously established, they used them in their own build systems. But none of them say that it is necessary to get stuff done.

I don’t think it’s necessary for a tutorial to have a disclaimer explicitly saying, “You don’t have to use the build tools we’re using to build OpenGL applications. It’s just for this one.”

Sorry, I might have misread in some of the tutorials I have looked at, and it might not apply to any tutorial that you have written.
What I meant is that I got the impression that graphics programming needed third-party tools, and as such would, in my mind, be unnecessary troublesome compared to plain, simple C/C++ programming.
Since that is not the case, I would at least expect that any fairly comprehensive, good tutorial wouldn’t leave such a misleading impression with it’s budding graphics programmers.

Hope that I have not completely misunderstood everything now.