链接IMGUI,SDL2的依赖性问题使用CMAKE进行项目

发布于 2025-02-06 17:31:56 字数 3196 浏览 2 评论 0原文

我很难将项目从SFML更改为SDL2+OpenGL3渲染。我当前的CMAKE设置遇到的错误是IMGUI没有链接到我的子文件夹,我在其中创建了共享库:UserInterface。 现在,我尝试将UserInterface声明为IMGUI库的依赖性:

(target_link_libraries(userInterface imgui))

没有它。 根据我的设置方式,我会遇到一些不同的错误,但是所有这些错误都必须是错误的:

没有行,我会得到一堆未定义的参考文献:

/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*)'

使用该行,我会得到:

/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

如果然后更改我的用户界面,而IMGUI则可以静态库我会收到此错误:

    /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

只是为了澄清,所有这些在链接CXX可执行数字时都链接错误, 这是我的应用。

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

我的最高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)

这是我的cmakelists.txt src文件夹中的cmakelists:

 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 )

cmakelists.txt userInterface内:

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


add_library(UserInterface STATIC ${USERINTERFACESOURCE})

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})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文