osgearth icon indicating copy to clipboard operation
osgearth copied to clipboard

ImGui.cpp not included in vcpkg builds

Open aliaksei135 opened this issue 3 years ago • 8 comments

OsgEarth 3.2 from vcpkg

It seems like ImGui.cpp is not included in the build as the implementations inside aren't being linked:

error LNK2019: unresolved external symbol "public: __cdecl osgEarth::GUI::OsgImGuiHandler::OsgImGuiHandler(void)" (??0OsgImGuiHandler@GUI@osgEarth@@QEAA@XZ) referenced in function "public: __cdecl osgEarth::GUI::ApplicationGUI::ApplicationGUI(bool)" (??0ApplicationGUI@GUI@osgEarth@@QEAA@_N@Z)
error LNK2001: unresolved external symbol "public: virtual bool __cdecl osgEarth::GUI::OsgImGuiHandler::handle(class osgGA::GUIEventAdapter const &,class osgGA::GUIActionAdapter &)" (?handle@OsgImGuiHandler@GUI@osgEarth@@UEAA_NAEBVGUIEventAdapter@osgGA@@AEAVGUIActionAdapter@5@@Z)
error LNK2019: unresolved external symbol "class osg::Node * __cdecl osgEarth::GUI::getSelectedNode(void)" (?getSelectedNode@GUI@osgEarth@@YAPEAVNode@osg@@XZ) referenced in function "public: virtual void __cdecl osgEarth::GUI::SceneGraphGUI::SceneHierarchyVisitor::apply(class osg::Group &)" (?apply@SceneHierarchyVisitor@SceneGraphGUI@GUI@osgEarth@@UEAAXAEAVGroup@osg@@@Z)
error LNK2019: unresolved external symbol "class std::vector<class osg::ref_ptr<class osg::Node>,class std::allocator<class osg::ref_ptr<class osg::Node> > > const & __cdecl osgEarth::GUI::getSelectedNodePath(void)" (?getSelectedNodePath@GUI@osgEarth@@YAAEBV?$vector@V?$ref_ptr@VNode@osg@@@osg@@V?$allocator@V?$ref_ptr@VNode@osg@@@osg@@@std@@@std@@XZ) referenced in function "public: bool __cdecl osgEarth::GUI::SceneGraphGUI::SceneHierarchyVisitor::isInSelectedNodePath(class osg::Node *)" (?isInSelectedNodePath@SceneHierarchyVisitor@SceneGraphGUI@GUI@osgEarth@@QEAA_NPEAVNode@osg@@@Z)
error LNK2019: unresolved external symbol "void __cdecl osgEarth::GUI::setSelectedNodePath(class std::vector<class osg::Node *,class std::allocator<class osg::Node *> > const &)" (?setSelectedNodePath@GUI@osgEarth@@YAXAEBV?$vector@PEAVNode@osg@@V?$allocator@PEAVNode@osg@@@std@@@std@@@Z) referenced in function "public: virtual void __cdecl osgEarth::GUI::SceneGraphGUI::SceneHierarchyVisitor::apply(class osg::Group &)" (?apply@SceneHierarchyVisitor@SceneGraphGUI@GUI@osgEarth@@UEAAXAEAVGroup@osg@@@Z)
fatal error LNK1120: 5 unresolved externals

aliaksei135 avatar Oct 07 '21 15:10 aliaksei135

I am not sure what is happening, do you see it in here: osgearth\src\third_party\imgui ?

Are you simply using vcpkg install osgearth:x64-windows or building osgearth and just using vcpkg dependencies?

Which platform are you using?

Thank you

plevy avatar Oct 07 '21 22:10 plevy

I'm installing osgearth:x64-windows from vcpkg on Win64. The project is setup to use vcpkg in manifest mode, but I can dig into the buildtrees and find osgearth\src\third_party\imgui.

I've dug into the vcpkg build output logs and it looks like it compiles the relevant files:

[446/477] C:\PROGRA~2\MICROS~3\2019\COMMUN~1\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe   /TP -DGEOS_INLINE -DH5_BUILT_AS_DYNAMIC_LIB -DOSGEARTH_ENABLE_IMGUI -DOSGEARTH_HAVE_MBTILES -DPROTOBUF_USE_DLLS -DUSE_UNSTABLE_GEOS_CPP_API -D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -IP:\Dev\vcpkg\buildtrees\osgearth\x64-windows-dbg\build_include -IP:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src -IP:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src\third_party\imgui -IP:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src\third_party\imgui\examples -IP:\Dev\vcpkg\installed\x64-windows\include -IP:\Dev\vcpkg\installed\x64-windows\include\geos -IP:\Dev\vcpkg\installed\x64-windows\include\cfitsio -IP:\Dev\vcpkg\installed\x64-windows\include\server -IP:\Dev\vcpkg\installed\x64-windows\include\libxml2 /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /GR /EHsc /MP  /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1  /fp:precise /showIncludes /Fosrc\applications\osgearth_imgui\CMakeFiles\application_osgearth_imgui.dir\__\__\third_party\imgui\imgui.cpp.obj /Fdsrc\applications\osgearth_imgui\CMakeFiles\application_osgearth_imgui.dir\ /FS -c P:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src\third_party\imgui\imgui.cpp
...
[471/477] C:\PROGRA~2\MICROS~3\2019\COMMUN~1\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe   /TP -DGEOS_INLINE -DH5_BUILT_AS_DYNAMIC_LIB -DOSGEARTH_ENABLE_IMGUI -DOSGEARTH_HAVE_MBTILES -DPROTOBUF_USE_DLLS -DUSE_UNSTABLE_GEOS_CPP_API -D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -IP:\Dev\vcpkg\buildtrees\osgearth\x64-windows-dbg\build_include -IP:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src -IP:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src\third_party\imgui -IP:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src\third_party\imgui\examples -IP:\Dev\vcpkg\installed\x64-windows\include -IP:\Dev\vcpkg\installed\x64-windows\include\geos -IP:\Dev\vcpkg\installed\x64-windows\include\cfitsio -IP:\Dev\vcpkg\installed\x64-windows\include\server -IP:\Dev\vcpkg\installed\x64-windows\include\libxml2 /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /GR /EHsc /MP  /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1  /fp:precise /showIncludes /Fosrc\applications\osgearth_imgui\CMakeFiles\application_osgearth_imgui.dir\__\__\osgEarth\ImGui\OsgImGuiHandler.cpp.obj /Fdsrc\applications\osgearth_imgui\CMakeFiles\application_osgearth_imgui.dir\ /FS -c P:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src\osgEarth\ImGui\OsgImGuiHandler.cpp
[472/477] C:\PROGRA~2\MICROS~3\2019\COMMUN~1\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe   /TP -DGEOS_INLINE -DH5_BUILT_AS_DYNAMIC_LIB -DOSGEARTH_ENABLE_IMGUI -DOSGEARTH_HAVE_MBTILES -DPROTOBUF_USE_DLLS -DUSE_UNSTABLE_GEOS_CPP_API -D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -IP:\Dev\vcpkg\buildtrees\osgearth\x64-windows-dbg\build_include -IP:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src -IP:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src\third_party\imgui -IP:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src\third_party\imgui\examples -IP:\Dev\vcpkg\installed\x64-windows\include -IP:\Dev\vcpkg\installed\x64-windows\include\geos -IP:\Dev\vcpkg\installed\x64-windows\include\cfitsio -IP:\Dev\vcpkg\installed\x64-windows\include\server -IP:\Dev\vcpkg\installed\x64-windows\include\libxml2 /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /GR /EHsc /MP  /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1  /fp:precise /showIncludes /Fosrc\applications\osgearth_imgui\CMakeFiles\application_osgearth_imgui.dir\__\__\osgEarth\ImGui\ImGui.cpp.obj /Fdsrc\applications\osgearth_imgui\CMakeFiles\application_osgearth_imgui.dir\ /FS -c P:\Dev\vcpkg\buildtrees\osgearth\src\06c3d361c0-b8e8458ce6.clean\src\osgEarth\ImGui\ImGui.cpp

Which leads me to believe there is something wrong with my project setup. My CMakeLists.txt is here:

...
find_package(imgui CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC imgui::imgui)

find_package(GLEW CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC GLEW::GLEW)

find_package(OpenSceneGraph REQUIRED osgDB osgGA osgSim osgViewer osgVolume osgUtil)
target_include_directories(${PROJECT_NAME} PUBLIC ${OPENSCENEGRAPH_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${OPENSCENEGRAPH_LIBRARIES})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND 
                ${CMAKE_COMMAND} ARGS -E copy_directory ${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/tools/osg/osgPlugins-3.6.5 ${CMAKE_BINARY_DIR})

set(OSGEARTH_ENABLE_IMGUI ON)
find_package(osgEarth REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ${OSGEARTH_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC osgEarth::osgEarth)
## This snippet is copied directly from the SETUP_IMGUI_APPLICATION macro, but doesn't make a difference 
## {
include_directories(
    ${GLEW_INCLUDE_DIR}
    ${OSGEARTH_SOURCE_DIR}/src/third_party/imgui
    ${OSGEARTH_SOURCE_DIR}/src/third_party/imgui/examples
)
set(TARGET_LIBRARIES_VARS
    ${TARGET_LIBRARIES_VARS}
    GLEW_LIBRARIES
)
set(TARGET_SRC
    ${OSGEARTH_SOURCE_DIR}/src/third_party/imgui/imgui.cpp
    ${OSGEARTH_SOURCE_DIR}/src/third_party/imgui/imgui_demo.cpp
    ${OSGEARTH_SOURCE_DIR}/src/third_party/imgui/imgui_draw.cpp
    ${OSGEARTH_SOURCE_DIR}/src/third_party/imgui/imgui_widgets.cpp
    ${OSGEARTH_SOURCE_DIR}/src/third_party/imgui/imgui_tables.cpp
    ${OSGEARTH_SOURCE_DIR}/src/third_party/imgui/backends/imgui_impl_opengl3.cpp
    ${OSGEARTH_SOURCE_DIR}/src/osgEarth/ImGui/OsgImGuiHandler.cpp
    ${OSGEARTH_SOURCE_DIR}/src/osgEarth/ImGui/ImGui.cpp
    ${TARGET_SRC}
)
## } 
...

aliaksei135 avatar Oct 11 '21 07:10 aliaksei135

OK, I have not tried building the whole tree in manifest so let me give that a try and see where it fails. Thank you

plevy avatar Oct 13 '21 16:10 plevy

Is OSGEARTH_SOURCE_DIR even being set to anything in VCPKG? That is something that is used internally to include the imgui based apps. If you are trying to build your own application you basically need to just make sure those files get included, either copy them manually into your project and include them or see if you can include them directly from vcpkg, but I have a feeling OSGEARTH_SOURCE_DIR is just evaluating to an empty string.

jasonbeverage avatar Oct 13 '21 16:10 jasonbeverage

Looks like @jasonbeverage is correct, calling message(${OSGEARTH_SOURCE_DIR}) throws an error, so it must be empty

aliaksei135 avatar Oct 15 '21 14:10 aliaksei135

Hello, i have a similiar problem:

on file "ImGui" (<VCPKG install dir>/installed\x64-windows\include\osgEarth\ImGui) i have a compiler error "C2653" on this row: " ImGui::Image((void*)(intptr_t)textureObject->_id, ImVec2(w, h), ImVec2(0, flip ? 0 : 1), ImVec2(1, flip ? 1 : 0), ImVec4(1, 1, 1, 1), ImVec4(1, 1, 0, 1));"

there is a workaround to build?

coderc264 avatar Jul 17 '22 09:07 coderc264

vcpkg build downloads the imgui source so perhaps that failed. Are you installing with the "tools" option?
vcpkg install osgearth[tools]:x64-windows?

plevy avatar Jul 18 '22 15:07 plevy

i ran these commands:

./vcpkg install osg:x64-windows ./vcpkg install osgearth:x64-windows

so without the [tools] option

coderc264 avatar Jul 20 '22 09:07 coderc264

Hello after the 3.4 version the problem it's still present, and it's worse because the workaround of include in my project a version of imgui don't work anymore

coderc264 avatar Jun 05 '23 08:06 coderc264

What do mean by doesn't work? Doesn't build or your application doesn't work?

vcpkg has always been a convenience rather than a dependency. If you would like to use 3rd party packages, you can go that route by manually setting paths in cmake. That is how we started and Openscenegraph had 3rd party binary packages for dependencies maintained by volunteers. vcpkg is more convenient than waiting for someone else to update their binary packages. On linux, it is easier to use packages from the repos than vcpkg.

plevy avatar Jun 05 '23 19:06 plevy

It's a libker error, i need to include the osgearth::Imagui code in my application to compile it without linker errors

coderc264 avatar Jun 06 '23 08:06 coderc264