0

Im having trouble changing my project from Sfml to SDL2+opengl3 rendering. The error im getting with my current CMake setup is ImGui not linking to a subfolder of mine in which i create a SHARED library: UserInterface. Now i have tried declaring UserInterface a dependency of ImGui library:

(target_link_libraries(UserInterface imgui))

and without it. I get a few different errors depending on how i set up CMake, but all of them must be wrong:

Without the line i get a bunch of undefined references:

/usr/bin/ld: UserInterface/libUserInterface.so: undefined reference to `ImGui_ImplOpenGL3_Init(char const*)'
/usr/bin/ld: UserInterface/libUserInterface.so: undefined reference to `ImGui::ShowDemoWindow(bool*)'

With that line i get:

/usr/bin/ld: ../libimgui.a(imgui_demo.cpp.o): relocation R_X86_64_PC32 against symbol `GImGuiDemoMarkerCallback' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value

If i then change my UserInterface, and imgui to STATIC libraries i get this error:

    /usr/bin/ld: libimgui.a(imgui_impl_opengl3.cpp.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libdl.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Just to clarify, all these are linking errors when linking CXX executable digitus, which is my application.

project:
         build
         CMakeLists.txt
         src (folder)
             CMakeLists.txt
             main.cpp
             (all required imgui files)
             UserInterface (folder)
                 CMakeLists.txt
                 [...]
             Action (folder)
                 [...]
         

My topmost CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)

set (CMAKE_CXX_STANDARD 17)
project(digitus)


set(CMAKE_MODULE_PATH "/usr/local/lib/cmake") # tell cmake where to find find.cmake and config.cmake files


find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED)
find_package(GLEW REQUIRED)
find_package(glm REQUIRED)


#include_directories(${SDL2_INCLUDE_DIR}) # add sdl2's include dir


add_subdirectory(src)

This is my CMakeLists.txt inside the src folder:

 SET(SOURCES
    main.cpp
    ApplicationManager.cpp
    ApplicationManager.h
    [...]
    )

SET( IMGUISOURCE
    imconfig.h 
    imgui_demo.cpp 
    imgui_draw.cpp 
    imgui_impl_opengl3_loader.h 
    imgui_impl_opengl3.cpp 
    imgui_impl_opengl3.h
    imgui_impl_sdl.cpp 
    imgui_impl_sdl.h 
    imgui_internal.h 
    imgui_tables.cpp 
    imgui_widgets.cpp 
    imgui.cpp 
    imgui.h 
    )
add_executable(digitus ${SOURCES})



target_link_libraries(digitus   glm::glm )
target_link_libraries(digitus ${CMAKE_DL_LIBS})

add_library(imgui ${IMGUISOURCE})
target_link_libraries(digitus imgui)

add_subdirectory(Action)
add_subdirectory(UserInterface)

#target_link_libraries(UserInterface imgui)
target_link_libraries(digitus UserInterface)
target_link_libraries(digitus Action)


target_link_libraries(digitus SDL2)

target_link_libraries(digitus  GLEW::glew)
target_link_libraries(digitus   OpenGL::GL )

The CMakeLists.txt inside UserInterface:

Set(USERINTERFACESOURCE
    UserInterface.h 
    UserInterface.cpp
    CircuitWindow.h 
    CircuitWindow.cpp
    )


add_library(UserInterface STATIC ${USERINTERFACESOURCE})
bonkt
  • 15
  • 1
  • 9
  • You got the second error - "undefined reference to symbol 'dlclose@@GLIBC_2.2.5'" - because **after** linkage to imgui, which uses that symbol, there is no linkage to dl library. Either move the line `target_link_libraries(digitus ${CMAKE_DL_LIBS})` to be after `target_link_libraries(digitus imgui)` or specify linkage for imgui library itself: `target_link_libraries(imgui ${CMAKE_DL_LIBS})`. In the latter case CMake will correctly propagate that linkage to `digitus` executable. – Tsyvarev Jun 12 '22 at 12:04
  • Yes, with this change (and STATIC imgui and userinterface) i get error: /usr/bin/ld: UserInterface/libUserInterface.so: undefined reference to `ImGui::InputText( [parameters])' collect2: error: ld returned 1 exit status So it seems im back where i started. about your comment, if im understanding correctly you say the error is because i link to the DL LIBS to my executabl, but only imgui actually uses it? why does linking libraries and then not using them create errors? seems excessive – bonkt Jun 12 '22 at 12:19
  • Thanks, i solved the last error by noticing there is some extra sneaky cpp files in Imgui that i needed to include: imgui_stdlib.h/cpp – bonkt Jun 12 '22 at 12:36

0 Answers0