cmakeglfwsteamos

Try to Install GLFW on Steam Deck


i have a Steam Deck and would like to install GLFW on a Steamdeck, so that VSCode can find the Libary, i use Cmake. I used Cmake on another linux machine with no problems. I think its related to the steam deck and steam os.

I a location in with the following files in usr/lib/cmake/glfw3 :

Also there are two header files in /usr/include/GLFW called:

Also i have this so's:

In the main.cpp file the #include <GLFW/glfw3.h> do not work.

My Cmake file looks now like this:

cmake_minimum_required(VERSION 3.12)
project(test)

# Add executable
add_executable(test src/main.cpp)

# Specify the path to GLFW include directory
set(GLFW_INCLUDE_DIR "/usr/include" CACHE PATH "Path to GLFW include directory")

# Specify the path to GLFW library directory
set(GLFW_LIBRARY_DIR "/usr/lib" CACHE PATH "Path to GLFW library directory")

# Add GLFW include directory
target_include_directories(test PRIVATE ${GLFW_INCLUDE_DIR})

# Link GLFW library to your executable
target_link_libraries(test ${GLFW_LIBRARY_DIR}/libglfw.so)

Maybe some one with a better understanding of cmake, c and linux can help me.

Thank you in advance.

I tried different combinations of cmake files with find() and so on. Looked into the internet, and used Chat GPT to find a solution. Reinstalled with

sudo pacman -S glfw-x11

glfw again on the steam deck.

EDIT:

Here is the full error when i start the building:

[main] Building folder: game_engine all
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/deck/Programming/game_engine/build --config Debug --target all --
[build] ninja: error: '/usr/lib/libglfw.so', needed by 'test', missing and no known rule to make it
[proc] The command: /usr/bin/cmake --build /home/deck/Programming/game_engine/build --config Debug --target all -- exited with code: 1
[driver] Build completed: 00:00:00.029
[build] Build finished with exit code 1

EDIT2:

When i safe the CMakeList.txt i get following message in VSCode:

[main] Configuring project: game_engine 
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++ -S/home/deck/Programming/game_engine -B/home/deck/Programming/game_engine/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: /home/deck/Programming/game_engine/build

Permission of usr/lib/libglfw.so:

with following command: ls -l libglfw.so lrwxrwxrwx 1 root root 12 Jul 23 2022 libglfw.so -> libglfw.so.3

EDIT3:

if i change my target_link_libraries(test ${GLFW_LIBRARY_DIR}/libglfw.so) to target_link_libraries(test $usr/lib/libglfw.so.3.3)

Permission is set to: -rwxr-xr-x 1 root root 278200 Jul 23 2022 /usr/lib/libglfw.so.3.3

Permission of /usr/include/GLFW/glfw3.h: -rw-r--r-- 1 root root 215860 Jul 23 2022 glfw3.h

i get this error in the build process:

[main] Building folder: game_engine 
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/deck/Programming/game_engine/build --config Debug --target all --
[build] [1/2  50% :: 0.022] Building CXX object CMakeFiles/test.dir/src/main.cpp.o
[build] FAILED: CMakeFiles/test.dir/src/main.cpp.o 
[build] /usr/bin/g++   -g -std=gnu++11 -MD -MT CMakeFiles/test.dir/src/main.cpp.o -MF CMakeFiles/test.dir/src/main.cpp.o.d -o CMakeFiles/test.dir/src/main.cpp.o -c /home/deck/Programming/game_engine/src/main.cpp
[build] /home/deck/Programming/game_engine/src/main.cpp:3:10: fatal error: GLFW/glfw3.h: No such file or directory
[build]     3 | #include <GLFW/glfw3.h>
[build]       |          ^~~~~~~~~~~~~~
[build] compilation terminated.
[build] ninja: build stopped: subcommand failed.
[proc] The command: /usr/bin/cmake --build /home/deck/Programming/game_engine/build --config Debug --target all -- exited with code: 1
[driver] Build completed: 00:00:00.054
[build] Build finished with exit code 1

Solution

  • I have found a solution for my System.

    1. Download GWFL Libary from https://www.glfw.org/
    2. Place it on the level of to cmake file of your project.

    Your Project would look like this: GraficsProgramDirectory

    -----src:
    ---------main.cpp

    -----CMakeLists.txt

    -----glfw-3.4

    1. Inside the CMake File is the following:
         make_minimum_required( VERSION 3.5 )
        
        project( test )
        
        set(OpenGL_GL_PREFERENCE "GLVND")
        
        find_package( OpenGL REQUIRED )
        
        include_directories( ${OPENGL_INCLUDE_DIRS} )
        
        set( GLFW_BUILD_DOCS OFF CACHE BOOL  "GLFW lib only" )
        set( GLFW_INSTALL OFF CACHE BOOL  "GLFW lib only" )
        set( GLAD_GL "" )
        
        add_subdirectory( glfw-3.4 )
        
        option( USE_GLAD "Use GLAD from GLFW" ON )
        
        if( USE_GLAD )
            include_directories("${GLFW_SOURCE_DIR}/deps")
            set( GLAD_GL "${GLFW_SOURCE_DIR}/deps/glad/gl.h" )
        endif()
        
        
        
        set( TEST_START
                src/main.cpp
                )
        
        add_executable( test  ${TEST_START} ${GLAD_GL} )
        target_link_libraries( test ${OPENGL_LIBRARIES} glfw )
    

    set(OpenGL_GL_PREFERENCE "GLVND") is only needed if cmake says it do find multiple OpenGL Libarys

    1. Build your project.

    I build this Solution with the Help of: https://github.com/juliettef/GLFW-CMake-starter