2

I am trying to build very simple application with Dear ImGui.

I copied some Dear ImGui files to my source directory and I compiled with CMake as follows.

cmake_minimum_required(VERSION 3.12)
project(imgui)

find_package(GLEW REQUIRED)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_executable(min 
    min.cpp
    ${CMAKE_SOURCE_DIR}/imgui.cpp
    ${CMAKE_SOURCE_DIR}/imgui_demo.cpp
    ${CMAKE_SOURCE_DIR}/imgui_draw.cpp
    ${CMAKE_SOURCE_DIR}/imgui_tables.cpp
    ${CMAKE_SOURCE_DIR}/imgui_widgets.cpp
    ${CMAKE_SOURCE_DIR}/imgui_impl_opengl3.cpp
    ${CMAKE_SOURCE_DIR}/imgui_impl_glfw.cpp
    )



target_link_libraries(min
    glfw
    GLEW 
    GL
    #${CMAKE_DL_LIBS} <If this command is used, build successfully!>
    )

But I got following error.

-- Configuring done
-- Generating done
-- Build files have been written to: /home/harumo/program/cpp/imgui/minimal/build
[ 11%] Linking CXX executable min
/usr/bin/ld: CMakeFiles/min.dir/imgui_impl_opengl3.cpp.o: undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/min.dir/build.make:189: min] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/min.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

If you have any other information you need, please let me know.

Thanks in advance!

  • 1
    Are you linking with `dl`? Run `cmake` in verbose mode so that we can see the actual commands it uses. – Ted Lyngmo Mar 20 '22 at 14:55
  • So, if you link with `dl` it works? What's the question about really? – Ted Lyngmo Mar 20 '22 at 15:32
  • imgui recommends static links and I would like to follow it. My question is how to build by simply listing source files in add_executable and libraries in target_link_libraries without `dl`. – Harumo Sasatake Mar 20 '22 at 15:47
  • CMake verbose mode gave me many messages, so I will post excerpts. ``` /usr/bin/clang++-12 CMakeFiles/min.dir/min.cpp.o CMakeFiles/min.dir/imgui.cpp.o CMakeFiles/min.dir/imgui_demo.cpp.o CMakeFiles/min.dir/imgui_draw.cpp.o CMakeFiles/min.dir/imgui_tables.cpp.o CMakeFiles/min.dir/imgui_widgets.cpp.o CMakeFiles/min.dir/imgui_impl_opengl3.cpp.o CMakeFiles/min.dir/imgui_impl_glfw.cpp.o -o min /usr/lib/x86_64-linux-gnu/libglfw.so.3.3 -lGLEW /usr/bin/ld: CMakeFiles/min.dir/imgui_impl_opengl3.cpp.o: undefined reference to symbol 'dlclose@@GLIBC_2.2.5' ``` – Harumo Sasatake Mar 20 '22 at 15:55
  • It appears that glfw is using the shared library version. Do you think this is the cause? – Harumo Sasatake Mar 20 '22 at 15:56

0 Answers0