Main Menu

Recent posts

#11
Installation help / Re: CMake cannot find SFML
Last post by texus - 27 March 2024, 22:36:48
QuoteI now have an issue with the example for the SFML backend, encountering an undefined reference to the bool runExample(tgui::BackendGui& gui) function.

The TGUI examples found in the "examples" folder are split into 2 parts. The first part contains just the main() function and shows how to initialize the window and gui (using backend-specific code, in this case using SFML Graphics). The second part is the "runExample" function that contains the code that is backend-independent and which is thus the same no matter whether you are using SFML, SDL or GLFW. The second part is found inside either the "scalable_login_screen" or "many_different_widgets" subfolder.

I'm guessing you only have a declaration like "bool runExample(tgui::BackendGui& gui);" in your current code. You can replace it with the following to have an example that compiles:
Code (cpp) Select
bool runExample(tgui::BackendGui& gui)
{
    return true;
}

The website contains some more example codes: https://tgui.eu/examples/latest-stable/
#12
Installation help / Re: CMake cannot find SFML
Last post by luka - 27 March 2024, 20:14:37
Quote from: texus on 27 March 2024, 19:28:51The library name passed to "target_link_libraries" should be either "TGUI::TGUI" (recommended)

I've managed to compile this file now.
#include <TGUI/TGUI.hpp>
#include <TGUI/Backend/SFML-Graphics.hpp>


int main()
{

}

I now have an issue with the example for the SFML backend, encountering an undefined reference to the bool runExample(tgui::BackendGui& gui) function.

[main] Building folder: AutoBackupScript2
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/build --config Debug --target all -j 6 --
[build] [ 77%] Built target tgui
[build] [ 81%] Building CXX object CMakeFiles/AutoBackupScript.dir/src/main.cpp.obj
[build] [ 96%] Built target gui-builder
[build] [100%] Linking CXX executable AutoBackupScript.exe
[build] C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\AutoBackupScript.dir/objects.a(main.cpp.obj): in function `main':
[build] C:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/src/main.cpp:41: undefined reference to `runExample(tgui::BackendGui&)'
[build] collect2.exe: error: ld returned 1 exit status
[build] mingw32-make[2]: *** [CMakeFiles\AutoBackupScript.dir\build.make:108: AutoBackupScript.exe] Error 1
[build] mingw32-make[1]: *** [CMakeFiles\Makefile2:132: CMakeFiles/AutoBackupScript.dir/all] Error 2
[build] mingw32-make: *** [Makefile:135: all] Error 2
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/build --config Debug --target all -j 6 -- exited with code: 2
[driver] Build completed: 00:00:05.274
[build] Build finished with exit code 2

Quote from: texus on 27 March 2024, 19:28:51The cmake command that is being executed has "-j 6" in it. Is this something you can change yourself? The log output would have been more clear if you ran it with "-j 1" (which you should only do when investigating an issue, as usually you do want to build with more threads). Now it builds your project and the gui builder at the same time so it prints both outputs interleaved and it isn't clear that the error is about your project and not the gui builder.

There is a way, is that something I should consider in general or is it more something for debugging?
#13
Installation help / Re: CMake cannot find SFML
Last post by texus - 27 March 2024, 19:28:51
The error isn't with the gui builder. If you set TGUI_BUILD_GUI_BUILDER to OFF then you would get the same error.

The library name passed to "target_link_libraries" should be either "TGUI::TGUI" (recommended) or "tgui" (deprecated), but "TGUI" is wrong.

The cmake command that is being executed has "-j 6" in it. Is this something you can change yourself? The log output would have been more clear if you ran it with "-j 1" (which you should only do when investigating an issue, as usually you do want to build with more threads). Now it builds your project and the gui builder at the same time so it prints both outputs interleaved and it isn't clear that the error is about your project and not the gui builder.
#14
Installation help / Re: CMake cannot find SFML
Last post by luka - 27 March 2024, 18:39:47
I deeply appreciate your assistance thus far. Nevertheless, I've encountered a snag with the GUI builder.

[main] Building folder: AutoBackupScript2
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/build --config Debug --target all -j 6 --
[build] [  3%] Linking CXX executable AutoBackupScript.exe
[build] [ 81%] Built target tgui
[build] C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lTGUI: No such file or directory
[build] collect2.exe: error: ld returned 1 exit status
[build] mingw32-make[2]: *** [CMakeFiles\AutoBackupScript.dir\build.make:104: AutoBackupScript.exe] Error 1
[build] mingw32-make[1]: *** [CMakeFiles\Makefile2:132: CMakeFiles/AutoBackupScript.dir/all] Error 2
[build] mingw32-make[1]: *** Waiting for unfinished jobs....
[build] [ 96%] Built target gui-builder
[build] mingw32-make: *** [Makefile:135: all] Error 2
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/build --config Debug --target all -j 6 -- exited with code: 2
[driver] Build completed: 00:00:00.913
[build] Build finished with exit code 2

#15
Help requests / Re: How can I load a font afte...
Last post by GetterSetter - 27 March 2024, 18:36:17
Okay, thank you for your comprehensive answer!
#16
Help requests / Re: How can I load a font afte...
Last post by texus - 27 March 2024, 18:32:04
You can just create a new font object:
Code (cpp) Select
tgui::Font font;
font = tgui::Font("font.ttf");

There is practically no performance cost in copying the Font object, as it is a lightweight object that will just share its internal resources between the different font objects.

Note that unlike Texture objects, creating multiple Font objects with the same filename will cause the file to be loaded multiple time. So to keep memory usage minimal, you should only call the tgui::Font("font.ttf") constructor once in your code and then just copy that font object to anywhere that you need it.
#17
Help requests / How can I load a font after cr...
Last post by GetterSetter - 27 March 2024, 17:49:51
Hello, I want to load the font after creating tgui::Font object, but I looked through the documentation and there are no such functions as loadFromFile() or loadFromMemory(). So I decided to do the following:
tgui::Font font;
font.getBackendFont()->loadFromFile("font.ttf");
but this leads to a segmentation fault. Are there any ways to do what I intend to do?
#18
Installation help / Re: CMake cannot find SFML
Last post by texus - 27 March 2024, 08:17:05
Now the log output looks more normal.
You need to move the set(SFML_DIR "c:/SFML/lib/cmake/SFML") line in your script to ABOVE the "add_subdirectory(TGUI)" line.

Also, your code should either contain "add_subdirectory(TGUI)" or "set(TGUI_DIR ...)\n find_package(TGUI 1 REQUIRED)", but not both of these.
#19
Installation help / Re: CMake cannot find SFML
Last post by luka - 27 March 2024, 00:07:41
I apologize for any confusion. I am new to CMake, so my knowledge is somewhat limited. I have only used CMake for incorporating SFML into two projects, and you can see how I did that in my CMakeLists.txt files, which compile without any issues. I referred to this blog post (https://www.ics.com/blog/find-and-link-libraries-cmake) to integrate the TGUI library, so I'm having a bit of trouble following your steps.

QuoteThe source directory is being set to the "TGUI" subdirectory, but the build directory is the one from your project? That would mean that it is trying to build TGUI and your own cmake script isn't even being executed.

I tried something different. Here is the orignale Cmakelists.txt:
cmake_minimum_required(VERSION 3.17)
project(AutoBackupScript VERSION 0.1.0 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)

include_directories(headers)
add_subdirectory(TGUI)

# Füge die Quelldateien hinzu
set(SOURCES
    src/main.cpp

)


# Füge das ausführbare Ziel hinzu und verlinke ImGui
add_executable(AutoBackupScript ${SOURCES})

set(TGUI_DIR "C:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/TGUI/cmake")
find_package(TGUI 1 REQUIRED)

target_link_libraries(AutoBackupScript PRIVATE TGUI)

# Suche und verlinke SFML
set(SFML_DIR "c:/SFML/lib/cmake/SFML")  # Pfad zum SFML CMake-Modul
find_package(SFML COMPONENTS system window graphics network audio REQUIRED)
if (SFML_FOUND)
    target_link_libraries(AutoBackupScript PRIVATE sfml-system sfml-window sfml-graphics sfml-network sfml-audio)
endif()

# Kopiere DLLs in das Build-Verzeichnis
if(WIN32)
    file(GLOB BINARY_DEP_DLLS "c:/SFML/bin/*.dll")
    file(COPY ${BINARY_DEP_DLLS} DESTINATION ${CMAKE_BINARY_DIR})
    file(GLOB MINGW_DEP_DLLS "C:/mingw64/bin/*.dll")
    file(COPY ${MINGW_DEP_DLLS} DESTINATION ${CMAKE_BINARY_DIR})
endif()


but i encountered a similar problem.
[main] Building folder: AutoBackupScript2
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/build --config Debug --target all -j 6 --
[build]
[build] Searching for SFML 2...
[build]
[build] -- Could NOT find SFML (missing: SFML_DIR)
[build]
[build] Searching for SFML 3...
[build]
[build] -- Could NOT find SFML (missing: SFML_DIR)
[build] CMake Error at TGUI/cmake/Dependencies.cmake:80 (message):
[build]   CMake couldn't find SFML.
[build]
[build]   Set SFML_DIR to the directory containing SFMLConfig.cmake (usually
[build]   something like SFML_ROOT/lib/cmake/SFML)
[build]
[build] Call Stack (most recent call first):
[build]   TGUI/cmake/Dependencies.cmake:93 (tgui_find_dependency_sfml)
[build]   TGUI/src/Backend/CMakeLists.txt:153 (tgui_add_dependency_sfml)
[build]   TGUI/src/CMakeLists.txt:305 (include)
[build]
[build]
[build] -- Configuring incomplete, errors occurred!
[build] mingw32-make: *** [Makefile:178: cmake_check_build_system] Error 1
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/build --config Debug --target all -j 6 -- exited with code: 2
[driver] Build completed: 00:00:00.482
[build] Build finished with exit code 2


Thank you for your time and assistance.
#20
Installation help / Re: CMake cannot find SFML
Last post by texus - 26 March 2024, 22:25:32
I'm a bit confused about how the project is being build.

The log contained the following line:
Quote[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=C:\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\mingw64\bin\g++.exe -SC:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/TGUI -Bc:/Users/luka-/OneDrive/Desktop/AutoBackupScript2/build -G "MinGW Makefiles"

The source directory is being set to the "TGUI" subdirectory, but the build directory is the one from your project? That would mean that it is trying to build TGUI and your own cmake script isn't even being executed.

If that command where to contain "-DSFML_DIR=c:/SFML/lib/cmake/SFML" then it would probably build TGUI successfully. However that would only build TGUI and not your project, so you probably want to change the source directory instead.