Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sfml and imgui with cmake and Clion  (Read 181 times)

0 Members and 1 Guest are viewing this topic.

YigitHamza

  • Newbie
  • *
  • Posts: 3
    • View Profile
Sfml and imgui with cmake and Clion
« on: December 24, 2023, 02:55:10 pm »
Hello i am a new developer  wants to learn sfml and imgui wits Cmake Clion i cant use imgui it gives error and the error says

====================[ Build | SFML | Debug ]====================================
"D:\JetBrains\CLion 2023.3.2\bin\cmake\win\x64\bin\cmake.exe" --build C:\Users\yigit\Desktop\projelerim\SFML\cmake-build-debug --target SFML -j 18
[1/1] Linking CXX executable SFML.exe
FAILED: SFML.exe and there is more line cmd.exe /C "cd . && C:\mingw64\bin\c++.exe -g  CMakeFiles/SFML.dir/main.cpp.obj -o SFML.exe -Wl,--out-implib,libSFML.dll.a -Wl,--major-image-version,0,--minor-image-version,0  C:/SFML/lib/libsfml-system-s-d.a  C:/SFML/lib/libsfml-window-s-d.a  C:/SFML/lib/libsfml-graphics-s-d.a  C:/SFML/lib/libsfml-audio-s-d.a  C:/SFML/lib/libsfml-window-s-d.a  -lOpenGL32  -lgdi32  C:/SFML/lib/libfreetype.a  C:/SFML/lib/libsfml-system-s-d.a  -lwinmm  C:/SFML/lib/libopenal32.a  C:/SFML/lib/libvorbisfile.a  C:/SFML/lib/libvorbisenc.a  C:/SFML/lib/libvorbis.a  C:/SFML/lib/libogg.a  C:/SFML/lib/libFLAC.a  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/SFML.dir/main.cpp.obj: in function `main':
C:/Users/yigit/Desktop/projelerim/SFML/main.cpp:9: undefined reference to `ImGui::SFML::Init(sf::RenderWindow&, bool)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/yigit/Desktop/projelerim/SFML/main.cpp:22: undefined reference to `ImGui::SFML::ProcessEvent(sf::Event const&)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/yigit/Desktop/projelerim/SFML/main.cpp:26: undefined reference to `ImGui::SFML::Update(sf::RenderWindow&, sf::Time)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/yigit/Desktop/projelerim/SFML/main.cpp:30: undefined reference to `ImGui::SFML::Render(sf::RenderWindow&)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/yigit/Desktop/projelerim/SFML/main.cpp:33: undefined reference to `ImGui::SFML::Shutdown()'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

the is a lot lines sorry my main Cmake codes
cmake_minimum_required(VERSION 3.27)
project(SFML)

set(CMAKE_CXX_STANDARD 17)

add_executable(SFML main.cpp)

set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR C:/SFML/lib/cmake/SFML)
find_package(SFML COMPONENTS system window graphics audio network REQUIRED)

include_directories(C:/SFML/include/SFML)
target_link_libraries(SFML sfml-system sfml-window sfml-graphics sfml-audio)
add_executable(Dynamic_2 ${CMAKE_CURRENT_SOURCE_DIR}/Main.cpp)
target_include_directories(
        SFML
        PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}/include
)

now there is my imgui file cmake codes

include(FetchContent)

set(SFML_VERSION 2.6.1)
set(IMGUI_VERSION 1.87)
#set(IMGUI_SFML_VERSION 2.6)

# It's nice to get stripped-down release zips instead of cloning
# a repo and checking out a tag
FetchContent_Declare(
        SFML
        URL "https://github.com/SFML/SFML/archive/${SFML_VERSION}.zip"
)

FetchContent_Declare(
        imgui
        URL "https://github.com/ocornut/imgui/archive/v${IMGUI_VERSION}.zip"
)

# Or by tag...
FetchContent_Declare(
        imgui-sfml
        GIT_REPOSITORY https://github.com/SFML/imgui-sfml.git
        GIT_TAG        2.6.x
        # GIT_COMMIT 5f54b69b6aee18db846c81633f86f78c2586dded
        # ^ or like this - sometimes it's better because FetchContent won't look
        # into remote to see if branch head was updated or not - good for stable
        # tags like 'vX.X' corresponding to releases
)

## finally, let's build

# SFML
option(SFML_BUILD_AUDIO "Build audio" OFF)
option(SFML_BUILD_NETWORK "Build network" OFF)
FetchContent_MakeAvailable(sfml)

# Dear ImGui
FetchContent_MakeAvailable(ImGui)

# ImGui-SFML
set(ImGui)
option(ImGui_SFML_FIND_SFML "Use find_package to find SFML" OFF)
option(ImGui_SFML_ImGui_DEMO "Build imgui_demo.cpp" ON)

FetchContent_MakeAvailable(imgui-sfml)

i taked the cmake codes from an other forum  if you can help me i appreciate it sory for my english its not my main language

« Last Edit: December 25, 2023, 09:25:30 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: Sfml and imgui with cmake and Clion
« Reply #1 on: December 25, 2023, 09:27:41 pm »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/