SFML/imgui-sfml

VS2019 Imgui/SFML with FetchContent failing to link properly

sarahkittyy opened this issue · 3 comments

When compiling I get unresolved external symbol "struct ImGuiContext * GImGui" (?GImGui@@3PEAUImGuiContext@@EA). Works just fine on linux. This is on VS2019 with CMake.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.13)
project(bq-r)
include(FetchContent)

# libs
set(SFML_VERSION "2.5.1")
FetchContent_Declare(
	sfml
	GIT_REPOSITORY "https://github.com/SFML/SFML.git"
	GIT_TAG "${SFML_VERSION}"
)
FetchContent_GetProperties(sfml)
if(NOT sfml_POPULATED)
	FetchContent_Populate(sfml)
	add_subdirectory(${sfml_SOURCE_DIR} ${sfml_BINARY_DIR})
endif()

FetchContent_Declare(
	imgui
	GIT_REPOSITORY https://github.com/ocornut/imgui
)

FetchContent_MakeAvailable(imgui)

FetchContent_Declare(
	imgui-sfml
	GIT_REPOSITORY https://github.com/eliasdaler/imgui-sfml
)

set(IMGUI_DIR ${imgui_SOURCE_DIR})
set(IMGUI_SFML_FIND_SFML OFF)
set(IMGUI_SFML_IMGUI_DEMO ON)
FetchContent_MakeAvailable(imgui-sfml)

# not libs
set(CMAKE_CXX_STANDARD 20)

file(GLOB_RECURSE sources "game/*.cpp")

set(includes "game/")
set(libs sfml-graphics sfml-window sfml-audio sfml-network sfml-system ImGui-SFML::ImGui-SFML)
set(flags)

add_executable(bq-r ${sources})

target_compile_options(bq-r PUBLIC ${flags})
target_include_directories(bq-r PUBLIC ${includes})
target_link_libraries(bq-r ${libs})

I've been up since midnight trying to figure this out lol. The linker error is referencing this file: https://github.com/sarahkittyy/blockquest-remake/blob/main/game/gui/editor_tile_button.cpp

Hello.
Check this out and see if this works for you: https://github.com/eliasdaler/imgui-sfml-fetchcontent/tree/master

If it does, see what your CMake build is doing differently and try to figure out what goes wrong.
Maybe something broke in the latest version of Dear ImGui? Try to use an older version.

I tried submodules, ExternalProject, FetchContent, all sorts of things, and what ended up working was just integrating manually, copying the imconfig-SFML.h over and including all the source files of both directly to the build

I don't believe that's a good long-term solution. Did you try the repo I've linked?
It should work, I think.