Help getting TGUI running - OpenGL

Started by johnnywz00, 01 May 2021, 03:39:34

johnnywz00

I'm using CodeLite 12.0.3 on MacOS 10.14.2, with SFML 2.5.1 (I think correctly) installed.
I can start a new project and paste in the minimal TGUI code and it will compile and open a blank window. However, the terminal displays this notice when it runs:

objc[9998]: Class SFViewController is implemented in both /Library/Frameworks/./sfml-window.framework/Versions/2.5.1/sfml-window (0x10fbd30a8) and /usr/local/lib/libsfml-window.2.5.dylib (0x10d8120a8). One of the two will be used. Which one is undefined.

, along with the same notice for about 7 other Classes.

Then, if I try to add a Button to the GUI object, it compiles, but in the terminal I get:

sfml-graphics requires support for OpenGL 1.1 or greater
Ensure that hardware acceleration is enabled if available


Do I need extra software or settings in order to run TGUI without any hitches? Thanks!
I should mention, that I'm pretty new to C++, so all the config is still a little bewildering for me...

John Ziegler

texus

The error about SFViewController means that your project is linking to both the SFML framework and the dylib file, while you should only link to one of them.

The opengl error is probably caused because one SFML version gets initialized properly while the second one isn't initialized and believes it has no opengl support.

In your project you are probably only linking to one of these versions, but TGUI will be linking to the other one. You need to make certain to use the same SFML version in your project and when building TGUI. So how did you install TGUI exactly?

johnnywz00

#2
I built TGUI from source with Cmake, but I don't remember all of the options I selected or deselected. I think I was going for using the dylibs. After building the source, I just went in to the CodeLite project Settings->Linker->Libraries and typed in "libtgui-d.0.9.1.dylib" in addition to the SFML dylibs that were there.

I tried erasing the SFML dylibs from that Libraries line (thinking maybe it was already using the frameworks?), but got a linker error:

Undefined symbols for architecture x86_64:
"sf::RenderWindow::RenderWindow(...
more


When I left the dylibs in the Libraries field and tried to manually remove the SFML frameworks from MacintoshHD/Library/Frameworks directory, it compiled but launching the minimal program failed with this message in the terminal:

dyld: Library not loaded: @rpath/sfml-graphics.framework/Versions/2.5.1/sfml-graphics
  Referenced from: /usr/local/lib/libtgui-d.0.9.1.dylib
  Reason: image not found
Abort trap: 6

Thanks for replying...

texus

#3
It seems like TGUI links to the frameworks then.

I don't think there is an easy way to choose whether TGUI links to dylibs or frameworks in CMake, it probably uses the first one it finds (unless you either set SFML_DIR manually or show the advanced options and manually change the paths of the SFML libraries).

So the solution is probably to either link to the SFML frameworks in your project, or to rebuild TGUI after removing the files from that Library/Frameworks folder (because TGUI will then find the SFML dylib files instead of the frameworks).
Edit: After thinking about it, TGUI might fail to find SFML when the frameworks are removed (when attempting to build TGUI with cmake again). There is an SFMLConfig.cmake file which TGUI finds and that one probably still points to the framework. So you would have to delete that file as well, or set SFML_DIR to a different location. Just keeping TGUI unchanged and linking to the SFML frameworks in your project thus sounds like the easier solution.

johnnywz00

Alas, I don't know how to tell my IDE to link to frameworks as opposed to dylibs. I tried pasting the framework filenames into the Linker Settings->Libraries: field, replacing the dylibs with them, but that didn't work.

I'm attaching a screenshot of the Cmake options that come preset. Can you possibly point to which ones I should modify that might correct this?
Sorry for the trouble! I'm no computer guru...

texus

I can't help you with that IDE. The only thing I know is how the command that is passed to the linker should look like: for dylibs it should be "-lXXX.dylib" while for frameworks it should be "-framework XXX".

To find a different SFML version you have to change the SFML_DIR option. The value has to be the directory that contains a file called SFMLConfig.hpp. I can't tell you which folder this is, as it depends on your SFML installation, but suppose SFML is installed to /usr/local then the folder would most likely be /usr/local/lib/cmake/SFML.

Alternatively you could always install SFML and TGUI using homebrew.

johnnywz00

Okay, I'll look into those options... thanks for your help!

johnnywz00

Working! Looking forward to exploring my C++ programming with your GUI...