I am learning Opengl by following the tutorial at https://learnopengl.com/ and I am having trouble setting up dependency with cmake(See Creating a window).
I based my CMakeLists.txt on the GLFW documentation.
cmake_minimum_required(VERSION 3.14)
project(openglTuto)
include_directories(include)
add_executable(gltuto src/main.c src/glad.c)
find_package(glfw3 3.3 REQUIRED)
find_package(OpenGL REQUIRED)
target_link_libraries(gltuto glfw)
target_include_directories(gltuto PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(gltuto ${OPENGL_gl_LIBRARY})
CMake succeed in building my configuration but ninja fail to compile and print an error.
[1/1] Linking C executable gltuto
FAILED: gltuto : && /usr/bin/cc CMakeFiles/gltuto.dir/src/main.c.o CMakeFiles/gltuto.dir/src/glad.c.o -o gltuto /usr/lib/libglfw.so.3.3 && :
/usr/bin/ld: CMakeFiles/gltuto.dir/src/glad.c.o: undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/bin/ld: /usr/lib/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
DSO missing from command line
is pretty obvious, you need to add-ldl
. Though that linker call is really weird in the first place, what with passing absolute paths to libraries. – Piloting