I am new to c++, I would like to get into practice of using opengl or GLFW, and also understand how to compile and link everything statically (I’m obsessed with the idea of having everything in an executable and being able to move from pc to pc) So far everywhere I look, I find tutorials based on using tools like visual studio, or cmake, (essentially tools that automate processes for you). I can see how those will be good when I understand what they’re doing for me, but as of right now, I think it’s essential I don’t skip fundamentals early on by relying on automated processes to do this for me. Is there any recommended resource as to where I can learn to compile and link libraries statically (specifically GLFW would really help) thanks.
There is really no need to use IDE or cmake with OpenGL or glfw. If you can write regular “hello world” program in C or C++ then you can write program that uses GL and glfw in same way. There is nothing special about GL and glfw from different libraries. Read up any guide how to use libraries for your compiler and you’ll be good to go.
For example, take this GLFW example code from here: https://www.glfw.org/documentation.html
First make sure you have glfw downloaded (for Windows) or installed with your system packages. Then save this example to
test.c. And then compile:
- on Linux:
gcc test.c -o test -lGL -lglfw3
- on Windows:
cl.exe test.c -Ipath/to/glfw/include OpenGL32.lib glfw3dll.lib
And you will get
test.exe as output.
If you wish to compile glfw from source, then easiest way is to follow documentation on how to use cmake: https://www.glfw.org/docs/latest/compile_guide.html As a result you will get static or shared library that you can keep around.
Would you know of any comprehensible guides for beginners on how to use a library for such case?