C++ OpenGL full setup on Arch Linux
I attempted to install OpenGL on Arch Linux. I wanted to know if I did it correctly because the documentation for Windows, Ubuntu, other Linux distributions has a lot more complex steps compared to what I did on my Arch machine.
1st Step:
Install GLFW3 from pacman sudo pacman -S glfw-x11.
2nd Step:
Add #include <GLFW/glfw3.h> to the top of my code
3rd Step:
Compile. Compiling results works as the book said. The pdf from https://learnopengl.com/. I did g++ main.cpp and ./a.out works.
Problem:
I did not have to link, cmake, etc anything. I followed the 3 steps and the normal g++ main.cpp and it still worked.
Did I do this correctly? Am I missing anything as for right now?
Problem 2:
I don't know where to find GLAD for OpenGL. It is not an Arch package. How can I install it for Arch?
Thank you.
About this post
- Posted
- Archived
- Score
- 79 · 97% up
- Kind
- Text
- ID
- m30743
26 comments
You need to generate the GLAD headers yourself. Put in your requirements into the GLAD generator, then download the output and include it in your project (put all the headers into your project tree and
#includethem).You can either install the GLAD generator through pip, or use it online at https://glad.dav1d.de/. (using the online generator is much easier)
It would make little sense trying to package GLAD, because you need a different GLAD for every combination of OpenGL versions and extensions.
Thank you, I already generated them. and included them as #include "glad/glad.h"
Deleted before we saved it.
You need GLFW and GLAD, not one or the other
Do you mean GLEW or GLAD?
GLAD
I can't link it. When I do
g++ main.cpp -o gl -lglfw3it errors```/usr/bin/ld: cannot find -lglfw3
collect2: error: ld returned 1 exit status``` I checked if pacman installed glfw-x11 and it did. and when I tried doing
which glfw-x11it said "no glfw-x11" what is happening???On ArchLinux glfw library is called "glfw", not "glfw3". So simply use
-lglfw- you can always check what files package has installed withpacman -Ql glfw-x11And you should consider using
pkg-configthat provides way to get flags for libraries automatically:I don't use GLFW and GLAD together? So I installed it on Arch correctly? only problem is linking?
I see what the book wants you to do. You can generate a GLAD header here and copy it into your project.
To compile you need to tell where the include files are for GLAD. To do that use -I ./include/glad and to compile add this to the end -ldl -GL -glfw. I would recommend you that you start to learn cmake while you are starting out or use this compile command as a script. I personally don't install glfw3 from repos and add it as a submodule itself, so when I compile my programs it builds glfw and then builds the program. Also remember to read the docs about glfw https://www.glfw.org/docs/latest/build_guide.html .
I am also pasting my CMakeLists.txt if you want it cmake_minimum_required(VERSION 3.19.1)
I actually prefer premake as to cmake, it's a shame premake isnt as wide as cmake
This is the first time I am hearing about it. Personally I don't want to deal with build systems alot I don't even have strong opinions on cmake. I have been watching Handmade Hero where the guy uses bat files to compile his code. For me build systems are a huge gateway to cross for a beginner to start a project.
Good try!!