Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use ImGui integration as subdirectory #75

Closed
photex opened this issue Sep 12, 2020 · 6 comments
Closed

How to use ImGui integration as subdirectory #75

photex opened this issue Sep 12, 2020 · 6 comments

Comments

@photex
Copy link

photex commented Sep 12, 2020

Howdy!

I can compile but not link the ImGui example currently (Windows, VS2019). I get linker errors regarding the event handlers in Context:

main.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl Magnum::ImGuiIntegration::Context::updateApplicationCursor<class Kpns::UI::MainWindow>(class Kpns::UI::MainWindow &)" (??$updateApplicationCursor@VMainWindow@UI@Kpns@@@Context@ImGuiIntegration@Magnum@@QEAAXAEAVMainWindow@UI@Kpns@@@Z) referenced in function "private: virtual void __cdecl Kpns::UI::MainWindow::drawEvent(void)" (?drawEvent@MainWindow@UI@Kpns@@EEAAXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol "public: bool __cdecl Magnum::ImGuiIntegration::Context::handleKeyPressEvent<class Magnum::Platform::GlfwApplication::KeyEvent>(class Magnum::Platform::GlfwApplication::KeyEvent &)" (??$handleKeyPressEvent@VKeyEvent@GlfwApplication@Platform@Magnum@@@Context@ImGuiIntegration@Magnum@@QEAA_NAEAVKeyEvent@GlfwApplication@Platform@2@@Z) referenced in function "private: virtual void __cdecl Kpns::UI::MainWindow::keyPressEvent(class Magnum::Platform::GlfwApplication::KeyEvent &)" (?keyPressEvent@MainWindow@UI@Kpns@@EEAAXAEAVKeyEvent@GlfwApplication@Platform@Magnum@@@Z)
main.cpp.obj : error LNK2019: unresolved external symbol "public: bool __cdecl Magnum::ImGuiIntegration::Context::handleKeyReleaseEvent<class Magnum::Platform::GlfwApplication::KeyEvent>(class Magnum::Platform::GlfwApplication::KeyEvent &)" (??$handleKeyReleaseEvent@VKeyEvent@GlfwApplication@Platform@Magnum@@@Context@ImGuiIntegration@Magnum@@QEAA_NAEAVKeyEvent@GlfwApplication@Platform@2@@Z) referenced in function "private: virtual void __cdecl Kpns::UI::MainWindow::keyReleaseEvent(class Magnum::Platform::GlfwApplication::KeyEvent &)" (?keyReleaseEvent@MainWindow@UI@Kpns@@EEAAXAEAVKeyEvent@GlfwApplication@Platform@Magnum@@@Z)
main.cpp.obj : error LNK2019: unresolved external symbol "public: bool __cdecl Magnum::ImGuiIntegration::Context::handleMousePressEvent<class Magnum::Platform::GlfwApplication::MouseEvent>(class Magnum::Platform::GlfwApplication::MouseEvent &)" (??$handleMousePressEvent@VMouseEvent@GlfwApplication@Platform@Magnum@@@Context@ImGuiIntegration@Magnum@@QEAA_NAEAVMouseEvent@GlfwApplication@Platform@2@@Z) referenced in function "private: virtual void __cdecl Kpns::UI::MainWindow::mousePressEvent(class Magnum::Platform::GlfwApplication::MouseEvent &)" (?mousePressEvent@MainWindow@UI@Kpns@@EEAAXAEAVMouseEvent@GlfwApplication@Platform@Magnum@@@Z)
main.cpp.obj : error LNK2019: unresolved external symbol "public: bool __cdecl Magnum::ImGuiIntegration::Context::handleMouseReleaseEvent<class Magnum::Platform::GlfwApplication::MouseEvent>(class Magnum::Platform::GlfwApplication::MouseEvent &)" (??$handleMouseReleaseEvent@VMouseEvent@GlfwApplication@Platform@Magnum@@@Context@ImGuiIntegration@Magnum@@QEAA_NAEAVMouseEvent@GlfwApplication@Platform@2@@Z) referenced in function "private: virtual void __cdecl Kpns::UI::MainWindow::mouseReleaseEvent(class Magnum::Platform::GlfwApplication::MouseEvent &)" (?mouseReleaseEvent@MainWindow@UI@Kpns@@EEAAXAEAVMouseEvent@GlfwApplication@Platform@Magnum@@@Z)
main.cpp.obj : error LNK2019: unresolved external symbol "public: bool __cdecl Magnum::ImGuiIntegration::Context::handleMouseMoveEvent<class Magnum::Platform::GlfwApplication::MouseMoveEvent>(class Magnum::Platform::GlfwApplication::MouseMoveEvent &)" (??$handleMouseMoveEvent@VMouseMoveEvent@GlfwApplication@Platform@Magnum@@@Context@ImGuiIntegration@Magnum@@QEAA_NAEAVMouseMoveEvent@GlfwApplication@Platform@2@@Z) referenced in function "private: virtual void __cdecl Kpns::UI::MainWindow::mouseMoveEvent(class Magnum::Platform::GlfwApplication::MouseMoveEvent &)" (?mouseMoveEvent@MainWindow@UI@Kpns@@EEAAXAEAVMouseMoveEvent@GlfwApplication@Platform@Magnum@@@Z)
main.cpp.obj : error LNK2019: unresolved external symbol "public: bool __cdecl Magnum::ImGuiIntegration::Context::handleMouseScrollEvent<class Magnum::Platform::GlfwApplication::MouseScrollEvent>(class Magnum::Platform::GlfwApplication::MouseScrollEvent &)" (??$handleMouseScrollEvent@VMouseScrollEvent@GlfwApplication@Platform@Magnum@@@Context@ImGuiIntegration@Magnum@@QEAA_NAEAVMouseScrollEvent@GlfwApplication@Platform@2@@Z) referenced in function "private: virtual void __cdecl Kpns::UI::MainWindow::mouseScrollEvent(class Magnum::Platform::GlfwApplication::MouseScrollEvent &)" (?mouseScrollEvent@MainWindow@UI@Kpns@@EEAAXAEAVMouseScrollEvent@GlfwApplication@Platform@Magnum@@@Z)
main.cpp.obj : error LNK2019: unresolved external symbol "public: bool __cdecl Magnum::ImGuiIntegration::Context::handleTextInputEvent<class Magnum::Platform::GlfwApplication::TextInputEvent>(class Magnum::Platform::GlfwApplication::TextInputEvent &)" (??$handleTextInputEvent@VTextInputEvent@GlfwApplication@Platform@Magnum@@@Context@ImGuiIntegration@Magnum@@QEAA_NAEAVTextInputEvent@GlfwApplication@Platform@2@@Z) referenced in function "private: virtual void __cdecl Kpns::UI::MainWindow::textInputEvent(class Magnum::Platform::GlfwApplication::TextInputEvent &)" (?textInputEvent@MainWindow@UI@Kpns@@EEAAXAEAVTextInputEvent@GlfwApplication@Platform@Magnum@@@Z)

My relevant CMake script that sets up Magnum:

##############################################################################
# Magnum (and it's associated subprojects)
#
set(BUILD_STATIC ON CACHE BOOL "" FORCE)

set(WITH_TESTSUITE OFF CACHE BOOL "" FORCE)
add_subdirectory(source/corrade EXCLUDE_FROM_ALL)

set(WITH_AUDIO OFF CACHE BOOL "" FORCE)
set(WITH_GLFWAPPLICATION ON CACHE BOOL "" FORCE)
add_subdirectory(source/magnum EXCLUDE_FROM_ALL)

set(WITH_EIGEN ON CACHE BOOL "" FORCE)
set(WITH_IMGUI ON CACHE BOOL "" FORCE)
set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source/imgui)
add_subdirectory(source/magnum-integration EXCLUDE_FROM_ALL)

set(WITH_PNGIMAGECONVERTER ON CACHE BOOL "" FORCE)
set(WITH_PNGIMPORTER ON CACHE BOOL "" FORCE)
add_subdirectory(source/magnum-plugins EXCLUDE_FROM_ALL)

And because I set this all up from a subdirectory under the repo root I provide a global interface library to avoid having to repeat myself for anything that uses Magnum:

add_library(kpns_graphics INTERFACE)
target_link_libraries(kpns_graphics INTERFACE
  Corrade::Main
  Magnum::GlfwApplication
  Magnum::GL
  Magnum::Magnum
  Magnum::Shaders
  Magnum::SceneGraph
  Magnum::DebugTools
  Magnum::Primitives
  Magnum::Text
  Magnum::TextureTools
  Magnum::Trade
  MagnumIntegration::ImGui
  MagnumIntegration::Eigen
  )

My application adds kpns_graphics to it's PRIVATE target_link_libraries.

So, everything compiles fine, CLion resolves all symbols etc. But when linking it fails and I'm not sure why. I'd appreciate any helpful advice.

Thanks!

@photex photex changed the title How to use ImGui integration as subdirectory *and* with BUILD_STATIC=ON? How to use ImGui integration as subdirectory Sep 12, 2020
@photex
Copy link
Author

photex commented Sep 12, 2020

I've just tested a fresh build and I get this error even when building using shared libraries.

@photex
Copy link
Author

photex commented Sep 14, 2020

Welp, I realized after some head scratching that I was including Context.h instead of Context.hpp. After using hpp my linker problems appear to be resolved... but none of the events appear to get handled or drawn correctly.

@mosra mosra added this to the 2020.0b milestone Sep 14, 2020
@mosra
Copy link
Owner

mosra commented Sep 14, 2020

Hi!

Glad you at least partially solved this already -- I wouldn't be able to discover that without seeing the source. Can you elaborate on how the events are incorrect? Are they not handled at all? Or are they happening at wrong positions? etc. Including relevant parts of the source code would help also, thanks! :)

@photex
Copy link
Author

photex commented Sep 14, 2020

😆 was just about to give an update.

I verified that the event callbacks and imgui context methods were all correctly getting called. I realized there must be another issue.
I had missed the call to redraw(). 🤦‍♀️

Onwards!

@mosra
Copy link
Owner

mosra commented Sep 14, 2020

Haha 😆

Good to see issues solving themselves if I take ages to reply.

@mosra
Copy link
Owner

mosra commented Sep 15, 2020

I just updated the docs to highlight those two common pitfalls a bit better: 1eae551 Not in the online docs yet, will do so in the next upload batch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants