Skip to content

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.

79 points24 comments
Open on Reddit
About this post
Posted
Archived
Score
79 · 97% up
Kind
Text
ID
m30743

Author

16
posts
37
comments
0
media
View profile

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 #include them).

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.

15 points

Thank you, I already generated them. and included them as #include "glad/glad.h"

3 points
unknown author

Deleted before we saved it.

7 points
  1. Yes, because you're not actually using any of the GLFW symbols. You'll run into linker errors if you try to use anything declared in the header.
  2. Are you using GLFW or GLAD? Decide on one or the other.
2 points

I can't link it. When I do g++ main.cpp -o gl -lglfw3 it 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-x11 it said "no glfw-x11" what is happening???

1 points

On ArchLinux glfw library is called "glfw", not "glfw3". So simply use -lglfw - you can always check what files package has installed with pacman -Ql glfw-x11

And you should consider using pkg-config that provides way to get flags for libraries automatically:

g++ main.cpp -o gl `pkg-config --libs --cflags glfw3`
3 points

I don't use GLFW and GLAD together? So I installed it on Arch correctly? only problem is linking?

1 points

I see what the book wants you to do. You can generate a GLAD header here and copy it into your project.

1 points

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)

project(shader_class)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/glfw)

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

add_executable(
    ${PROJECT_NAME}
    ${CMAKE_CURRENT_SOURCE_DIR}/app/main.c
    ${CMAKE_CURRENT_SOURCE_DIR}/src/glad.c
    ${CMAKE_CURRENT_SOURCE_DIR}/src/shader.c
    )

target_include_directories(
    ${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${PROJECT_NAME} PUBLIC 
    ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw/include
    )

target_link_directories(
    ${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw/src
    )

target_link_libraries(
    ${PROJECT_NAME} glfw GL dl
    )
2 points

I actually prefer premake as to cmake, it's a shame premake isnt as wide as cmake

1 points

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.

2 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.