cmake error can't find raylib for backend

Started by MattDA, 29 September 2024, 18:37:54

MattDA

Hello. I am trying to install the latest tgui for use with Raylib. In cmake gui cmake can not find the bin dir because it does not exist in my raylib 5 build.In the "selecting a back end" docs, "lib/cmake/raylib/raylib-config.cmake must exists." This directory does not exist in any of my raylib builds or the pre built package. I can see the raylib-config.cmake in another folder but when I tried so set that as raylibs path cmake gui considered it but rejected the file.   


Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
CMake Error at cmake/Dependencies.cmake:600 (find_package):
  Could not find a package configuration file provided by "raylib" with any
  of the following names:

    raylibConfig.cmake
    raylib-config.cmake

  Add the installation prefix of "raylib" to CMAKE_PREFIX_PATH or set
  "raylib_DIR" to a directory containing one of the above files.  If "raylib"
  provides a separate development package or SDK, be sure it has been
  installed.
Call Stack (most recent call first):
  src/Backend/CMakeLists.txt:204 (tgui_add_dependency_raylib)
  src/CMakeLists.txt:312 (include)


Configuring incomplete, errors occurred!


texus

#1
Do you use CMake to build raylib? What build system are you using?
On Linux with Makefiles for example, the config file will be created when running "make install". If you use e.g. visual studio then you will probably also have some INSTALL target that you can build.

Edit: you might also want to try setting raylib_DIR to the directory of the config file instead of raylib_ROOT just to be safe (the DIR variable will work with any cmake version, the ROOT version is a newer feature).

texus

I've updated TGUI to provide an alternative to the raylib-config.cmake file.
You can now use the pre-built package by setting raylib_INCLUDE_DIR to the include folder and raylib_LIBRARY to one of the files inside the lib folder.

MattDA

Thank you for responding. I tried the updated tgui-1.x. I am using cmake GUI and vs community 2022 with ms compilers. The raylib pre-built is from https://github.com/raysan5/raylib/releases/tag/5.0 and the file is raylib-5.0_win64_msvc16.zip. Using your updated tgui I was able to build the solution in cmake gui with the raylib back end and paths as you stated.
I linked in VS and can see no errors in my project which is from the minimal example from tgui.eu. It all looks good but when I try to compile the project now I get a link error.
error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl tgui::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@tgui@@QEAA@EEEE@Z)

I should also mention that raylib its self compiled and linked fine. Thanks again for helping. Any Idea why I am still having link issues?   

texus

Is that the only linking error, or one of many?
Did you add the TGUI library to your linker?
Are you using static or dynamic libraries?

MattDA

I have tried a new cmake and vs build and got errors when I set the raylib_LIB to raylib.dll. raylibdll.dll I guess is for shared? Anyhow I am working on it. I will update.

//configuration
//CMake settings
//  Build shared checked
//  raylib_INCLUD_DIR C:/raylib-5.0_win64_msvc16/raylib/include
//  raylib_LIBRARY C:/raylib-5.0_win64_msvc16/raylib/lib/raylibdll.lib


texus

#6
raylibdll.lib is the shared library, raylib.lib is the static one.
Trying to set raylib_LIBRARY to raylib.dll is wrong so getting errors in that case makes sense.

If it's only the Color class that is giving the linker error then you can try setting TGUI_CXX_STANDARD to 17 in CMake when building TGUI. I've never seen that linker error before though, it only makes sense to me if you aren't linking to TGUI or if you are incorrectly defining TGUI_STATIC, but in those cases you would get many more linker errors. The error also has nothing to do with raylib, it's purely with linking TGUI itself, so I guess the raylib part is fine now.

MattDA

#7
I finally got a debug shared build up and running. I think I linked to raylib.lib from cmake gui in stead of raylibdll.lib when building the previous TGUI solution. Any how I have the "Many different widgets" code in my project. Everything works except loading the background image. TGUI will load "RedBackground.jpg but does not work with any other images that I have tried. I can't imagine why I could load some images and not others. DPI is the only real difference I see. The RedBackground.jpg is higher DPI than the ones I have tried. Would this be related to cmake settings maybe?
 

texus

Loading images is unrelated to any CMake settings.

Do you get a specific error message when loading the images?
TGUI uses stb_image to load the image as RBGA pixels in memory, and then passes these pixels to raylib. During the automated tests, TGUI loads multiple images from https://github.com/texus/TGUI/tree/1.x/tests/resources which include a .jpg, .bmp and .png image. You would need some special type of image before stb_image will fail to load it.

Have you placed your images in the same directory as the RedBackground.jpg file to rule out the possibility that something is wrong with the path to your images?

MattDA

I get a TGUI exeption from the Try Catch block. The error is at line...
  gui.add(tgui::Picture::create("themes\\Ground.jpg"));

TGUI Exception: Failed to load 'themes/Ground.jpg'

themes is currently in the same directory as the executable. Ground.jpg is in themes with RedBackground. I tried with forward slash as well. It can find the image just won't load it. In addition to putting it in the same directory as the RedBackground, I tried to just modify the RedBackground and replaced it with the same name and that would not load either.   

texus

Could you attach your Ground.jpg image then so that I can take a look where the loading fails?

MattDA

#11
It seems that it will not load any image that did not come from the original theme folder. Trying different images I can load the BabyBlue.png, RedBackground, and even a button from the development folder.
//tgui::Picture::Ptr picPtr = tgui::Picture::create("themes/newCrack_albedo.jpg"); //nope
//tgui::Picture::Ptr picPtr = tgui::Picture::create("themes/Ground.jpg");//nope
//tgui::Picture::Ptr picPtr = tgui::Picture::create("themes/ground.jpg");//nope
tgui::Picture::Ptr picPtr = tgui::Picture::create("themes/RedBackground.jpg");//Works
//tgui::Picture::Ptr picPtr = tgui::Picture::create("themes/RedBackground.png");//nope
//tgui::Picture::Ptr picPtr = tgui::Picture::create("themes/BabyBlue.png");//Works
//tgui::Picture::Ptr picPtr = tgui::Picture::create("C:\\Users\\Mattd\\Documents\\MyCode\\RaylibTest3\\x64\\Debug\\themes\\development\\Black\\images\\ButtonBackgroundFocused.png");//Works
//tgui::Picture::Ptr picPtr = tgui::Picture::create("themes\\development\\Black\\images\\ButtonBackgroundFocused.png");//Works
I will post the image as soon as I figure out how.



 



MattDA

#13


texus

I can load the image in a Picture widget (with the raylib backend) here without any issues. So I have no idea what the issue could be.

Have you tried opening the JPG files with some image editors and re-saving them?
Maybe you can try converting the image to PNG and load that file instead of the JPEG?

MattDA

It has something to do with windows security blocking my c++ app. I know because if I run my exe as administrator it works. I am not sure how to whitelist vs or vs projects, I guess its time to find out. Thanks for your help.