Trouble bundling OSX App with CMake

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

User avatar
DeadlyGoatGames
Just popping in
Just popping in
Posts: 4
Joined: Sat Oct 07, 2017 14:35

Trouble bundling OSX App with CMake

Postby DeadlyGoatGames » Sat Oct 07, 2017 15:07

Hi guys,

I've been searching and bashing my head on this for the last two weeks and would love some help. I'd even pay someone at this point (no joke) just to make progress and move back to the actual coding of my game again. This is my first post here too, so sorry if I miss some information.
I'd be happy to copy and paste any more relevant code samples. Desperation aside, let me begin:

Problem: I have a fairly simple game I'm starting and want to build an App file to distribute for testing etc. on another machine. My game is using CEGUI and only really seems to have trouble properly linking / bundling CEGUI in a way that can work on another computer. The game does run fine from where it builds to before attempting the bundle because it was finding CEGUI dylibs from "@executable_path/../Frameworks" and I copied all the dependencies that were built to a folder to match this in my project directory.

How I built/installed CEGUI: I'm using OSX and cloned both the CEGUI and CEGUI-dependencies repositories and then switched to the 0.8.x branches. Inside the dependencies project, I created a new "build" folder, cd to it, and run "cmake ..". After it finishes, I build it with just "make". Once dependencies are built, I go to cegui, make the "build" folder, make a new symbolic link to cegui-dependencies/build/dependencies as "dependencies" in the cegui directory, cd to my new build directory and "cmake ..", "make", and "sudo make install". This might be part of my problem, I know on other posts / docs that it was recommended not to install. But, I've chosen to install it because I don't know how else I am to get my project to find CEGUI at all.

After a bit of searching, I did find a "FindCEGUI.cmake" file that I put in with my other cmake scripts in my project. I found that this does seem to pick up my CEGUI dylibs from the install location just fine, so I feel good there.

The problems started happening as I now wanted to learn how to make the bundle for OSX. I quickly discovered "fixup_bundle" and with some trial and error I eventually got this to find my App file and go. I've added /usr/local/lib to my directories it searches for libraries and it ends up finding everything just fine. But, it won't find the CEGUI dependency dylibs (yet another problem!).

So, with much more trial and error, I've set up some CMake to copy these over:

Code: Select all

SET(FRAMEWORKS
    # "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libCEGUIBase-0.dylib"
    # "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libCEGUICommonDialogs-0.dylib"
    # "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libCEGUICoreWindowRendererSet.dylib"

    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libCEGUIExpatParser.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libCEGUIOpenGLRenderer-0.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libCEGUISILLYImageCodec.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libexpat.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libfreetype.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libglew.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libglfw.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libjpeg.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libpcre.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libpng.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libSILLY.dylib"
    "${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/libzlib.dylib"
)
    SET_SOURCE_FILES_PROPERTIES(${FRAMEWORKS}
        PROPERTIES MACOSX_PACKAGE_LOCATION MacOS
    )
   
    ADD_EXECUTABLE(${PROJECT_NAME} MACOSX_BUNDLE ${SOURCES} ${FRAMEWORKS} ${RESOURCES})



You might notice that I'm actually copying to "MacOS" instead of "Resources" or really "Frameworks" like the default setting is looking for. I had trouble with fixup_bundle ignoring my files I copied to Frameworks and just adding yet another copy to the executable location (MacOS). So, I rebuilt CEGUI with the option to change the install name to just "@executable_path" and now I don't have duplicate CEGUI libraries being pulled in at least.

So, here's where my crazy problems all begin and the last week now has been mostly trying to figure out this dylib linking mess. I've gone with trying to copy just the minimum amount of dylibs (above script) one by one until it runs and it'll be great on my computer. But, somewhere something is still referencing a dylib installed at /usr/local/lib/cegui-0.8 again and I can't find it with otool -L on all the files either. So, this won't work well.

Here's the type of error for this that I typically see:

Code: Select all

CEGUI::GenericException in function 'CEGUI::DynamicModule::DynamicModule(const
CEGUI::String &)'
(/Users/[username]/CEGUI/cegui/cegui/src/DynamicModule.cpp:224) : Failed to
load module 'libCEGUIExpatParser.dylib':
dlopen(/usr/local/lib/cegui-0.8/libCEGUIExpatParser.dylib, 1): image not found
libc++abi.dylib: terminating with uncaught exception of type
CEGUI::GenericException: CEGUI::GenericException in function
'CEGUI::DynamicModule::DynamicModule(const CEGUI::String &)'
(/Users/timmendenhall/CEGUI/cegui/cegui/src/DynamicModule.cpp:224) : Failed to
load module 'libCEGUIExpatParser.dylib':
dlopen(/usr/local/lib/cegui-0.8/libCEGUIExpatParser.dylib, 1): image not found
zsh: abort      ./RpgClient.app/Contents/MacOS/RpgClient ''


I've also tried not copying any of the libraries over with that crazy scripts and just let fixup_bundle find it and I generally still get the same dynamicModule issue. I'll sometimes just get a plain Seg Fault when trying to run the executable directly via running it directly in console ./RpgClient.app/Contents/MacOs/RpgClient.

Did I miss some best practices on including CEGUI in a project of your own that is using Cmake and plan on bundling? What can I do as some next steps to try? I'm currently trying a 3rd build of CEGUI with "@rpath" as the install_name and trying to figure out if I can somehow make CMake agree with that now. But, it's giving me issues with trying to use my binary install directory to look up my resources now instead of resources folder like before (using SDL_GetBasePath())

Here's just the essentials of the CEGUI.log from when it does run successfully. Which I can usually do by not running make install and then running the executable directly in console. Opening the App file breaks under most things I've tried still besides my first example of failure above. Which was the closest and most excited I was for having this "work" until I tried another computer haha.

Code: Select all

07/10/2017 05:48:55 (Std)    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
07/10/2017 05:48:55 (Std)    +                     Crazy Eddie's GUI System - Event log                    +
07/10/2017 05:48:55 (Std)    +                          (http://www.cegui.org.uk/)                         +
07/10/2017 05:48:55 (Std)    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

07/10/2017 05:48:55 (Std)    CEGUI::Logger singleton created. (0x7fe60d469c90)
07/10/2017 05:48:55 (Std)    
07/10/2017 05:48:55 (Std)    ********************************************************************************
07/10/2017 05:48:55 (Std)    * Important:                                                                   *
07/10/2017 05:48:55 (Std)    *     To get support at the CEGUI forums, you must post _at least_ the section *
07/10/2017 05:48:55 (Std)    *     of this log file indicated below.  Failure to do this will result in no  *
07/10/2017 05:48:55 (Std)    *     support being given; please do not waste our time.                       *
07/10/2017 05:48:55 (Std)    ********************************************************************************
07/10/2017 05:48:55 (Std)    ********************************************************************************
07/10/2017 05:48:55 (Std)    * -------- START OF ESSENTIAL SECTION TO BE POSTED ON THE FORUM       -------- *
07/10/2017 05:48:55 (Std)    ********************************************************************************
07/10/2017 05:48:55 (Std)    ---- Version: 0.8.7 (Build: Oct  4 2017 Apple Mac g++ 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37) 64 bit) ----
07/10/2017 05:48:55 (Std)    ---- Renderer module is: CEGUI::OpenGL3Renderer - Official OpenGL 3.2 core based renderer module.  TextureTarget support enabled via FBO OGL 3.2 core implementation. ----
07/10/2017 05:48:55 (Std)    ---- XML Parser module is: CEGUI::ExpatParser - Official expat based parser module for CEGUI ----
07/10/2017 05:48:55 (Std)    ---- Image Codec module is: SILLYImageCodec - Official SILLY based image codec ----
07/10/2017 05:48:55 (Std)    ---- Scripting module is: None ----
07/10/2017 05:48:55 (Std)    ********************************************************************************
07/10/2017 05:48:55 (Std)    * -------- END OF ESSENTIAL SECTION TO BE POSTED ON THE FORUM         -------- *
07/10/2017 05:48:55 (Std)    ********************************************************************************

User avatar
DeadlyGoatGames
Just popping in
Just popping in
Posts: 4
Joined: Sat Oct 07, 2017 14:35

Re: Trouble bundling OSX App with CMake

Postby DeadlyGoatGames » Sat Oct 07, 2017 17:43

Sorry if this bad practice to post a reply versus edit. But, I wanted to jump back in and say I'm going to work on a public github repository with a minimal amount of code and resources to replicate what I got going on here. Thanks again in advance to anyone looking at this!

User avatar
DeadlyGoatGames
Just popping in
Just popping in
Posts: 4
Joined: Sat Oct 07, 2017 14:35

Re: Trouble bundling OSX App with CMake

Postby DeadlyGoatGames » Sat Oct 07, 2017 19:22

I have created the repository here https://github.com/deadlygoat/cegui-app with some notes probably duplicated on the README file there. In the current state, you can do a regular "cmake ..", "make" and make an App file that'll run fine on my computer. But, after "make install" it won't work and throws this (I think it's related to me not doing rpath or the build right still).

Code: Select all

Application Specific Information:
abort() called
terminating with uncaught exception of type CEGUI::GenericException: CEGUI::GenericException in function 'CEGUI::DynamicModule::DynamicModule(const CEGUI::String &)' (/Users/[username]/CEGUI/cegui/cegui/src/DynamicModule.cpp:224) : Failed to load module 'libCEGUISILLYImageCodec.dylib': dlopen(/usr/local/lib/cegui-0.8/libCEGUISILLYImageCodec.dylib, 1): Library not loaded: @rpath/libSILLY.dylib
  Referenced from: /usr/local/lib/cegui-0.8/libCEGUISILLYImageCodec.dylib
  Reason: image not found

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Trouble bundling OSX App with CMake

Postby Ident » Mon Oct 09, 2017 08:33

I dont use MacOS unfortunately, but assuming the same issues can occur there as they can on Windows: Did you maybe mix up debug and release dynamic libraries? Are you sure you are distributing the right dynamic libraries in what you run on other machines?

The exception message says the dyn lib is missing. So is it present in the same folder? Is there a way on MacOS to load libraries from absolute folders and was your project set up in such a way?
CrazyEddie: "I don't like GUIs"

User avatar
DeadlyGoatGames
Just popping in
Just popping in
Posts: 4
Joined: Sat Oct 07, 2017 14:35

Re: Trouble bundling OSX App with CMake

Postby DeadlyGoatGames » Tue Oct 10, 2017 23:51

Indent, thank you for replying! I haven't got around to trying to make this work lately, but, I'm going to try more out by the weekend for sure. I'm still a little new to CMake and the idea of bundling my own applications, etc. by hand. If I end up making some more progress I'll be sure to post back in the hopes of helping anyone else.

Thanks again! I love CEGUI so far, even with this little hiccup it's nice having a tried and proven system for UI versus writing our own.

Edit: After running "cmake", "make", and "make install" on that repository I linked above, I get this error:

Code: Select all

build master % ./CEGUIApp.app/Contents/MacOS/CEGUIApp
CEGUI::GenericException in function 'CEGUI::DynamicModule::DynamicModule(const CEGUI::String &)' (/Users/timmendenhall/CEGUI/cegui/cegui/src/DynamicModule.cpp:224) : Failed to load module 'libCEGUISILLYImageCodec.dylib': dlopen(/usr/local/lib/cegui-0.8/libCEGUISILLYImageCodec.dylib, 1): Library not loaded: @rpath/libSILLY.dylib
  Referenced from: /usr/local/lib/cegui-0.8/libCEGUISILLYImageCodec.dylib
  Reason: image not found


I think there's two things I'm confused about that I need to learn before I can figure out how to fix my CMakeLists.txt.

1) I don't know why a dylib is being opened here: /usr/local/lib/cegui-0.8/libCEGUISILLYImageCodec.dylib when it should have been "fixed" by CmakeUtilities "fixup_bundle". If I check my references on the executable it's basically checking the relative path of the executable, going up and then back into the executable folder (MacOS) and looking for the libraries there. The librares are there as expected along side the executable.

Code: Select all

MacOS master % otool -L CEGUIApp
CEGUIApp:
   @executable_path/../MacOS/libSDL2-2.0.0.dylib (compatibility version 7.0.0, current version 7.0.0)
   /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
   @executable_path/../MacOS/libGLEW.2.1.dylib (compatibility version 2.1.0, current version 2.1.0)
   /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
   @executable_path/../MacOS/libCEGUIBase-0.dylib (compatibility version 0.0.0, current version 0.0.0)
   @executable_path/../MacOS/libCEGUIOpenGLRenderer-0.dylib (compatibility version 0.0.0, current version 0.0.0)
   @executable_path/../MacOS/libCEGUISILLYImageCodec.dylib (compatibility version 0.0.0, current version 0.0.0)
   @executable_path/../MacOS/libCEGUIExpatParser.dylib (compatibility version 0.0.0, current version 0.0.0)
   /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
   /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)


2) The "Library not loaded: @rpath/libSILLY.dylib" part makes me think I'm just not knowing how to use @rpath right possibly? When I go around and otool -L on the dynamic libraries I haven't noticed anything that's referencing my installed library location. I do see the libSILLY.dylib in the MacOS folder alongside the executable. So, why is it being referenced as just "@rpath" here instead of filling in the relative path?

Here's some of my madness trying to track the dynamic library references going backwards, as you see here it should be referencing libSILLY where it actually is:

Code: Select all

MacOS master % otool -L libCEGUISILLYImageCodec.dylib
libCEGUISILLYImageCodec.dylib:
   @executable_path/../MacOS/libCEGUISILLYImageCodec.dylib (compatibility version 0.0.0, current version 0.0.0)
   @executable_path/../MacOS/libSILLY.dylib (compatibility version 0.0.0, current version 0.0.0)
   @executable_path/../MacOS/libCEGUIBase-0.dylib (compatibility version 0.0.0, current version 0.0.0)
   /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
   @executable_path/../MacOS/libfreetype.dylib (compatibility version 0.0.0, current version 0.0.0)
   @executable_path/../MacOS/libpcre.dylib (compatibility version 0.0.0, current version 0.0.0)
   /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
   /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)


Code: Select all

libSILLY.dylib:
   @executable_path/../MacOS/libSILLY.dylib (compatibility version 0.0.0, current version 0.0.0)
   @executable_path/../MacOS/libpng.dylib (compatibility version 0.0.0, current version 0.0.0)
   @executable_path/../MacOS/libjpeg.dylib (compatibility version 0.0.0, current version 0.0.0)
   @executable_path/../MacOS/libzlib.dylib (compatibility version 0.0.0, current version 0.0.0)
   /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
   /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)


And now the kicker in my confusion is I get a seg fault if I try to just run the executable while I'm already in the directory of the executable itself. Which makes me think I need to setup the @loader_path or @rpath stuff better. But, I'm confused on why the seg. fault. Here's that though:

Code: Select all

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       EXC_I386_GPFLT
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [0]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libjpeg.9.dylib                  0x000000010da1d1f8 jpeg_CreateDecompress + 32
1   libSILLY.dylib                   0x000000010da081cd SILLY::JPGImageContext::JPGImageContext() + 125
2   libSILLY.dylib                   0x000000010da08439 SILLY::JPGImageLoader::loadHeader(SILLY::PixelFormat&, SILLY::DataSource*) + 41
3   libSILLY.dylib                   0x000000010da07462 SILLY::Image::loadImageHeader() + 82
4   libCEGUISILLYImageCodec.dylib    0x000000010d8bdc92 CEGUI::SILLYImageCodec::load(CEGUI::RawDataContainer const&, CEGUI::Texture*) + 66
5   libCEGUIOpenGLRenderer-0.dylib   0x000000010d88f639 CEGUI::OpenGLTexture::loadFromFile(CEGUI::String const&, CEGUI::String const&) + 105
6   libCEGUIOpenGLRenderer-0.dylib   0x000000010d88dbcd CEGUI::OpenGLTexture::OpenGLTexture(CEGUI::OpenGLRendererBase&, CEGUI::String const&, CEGUI::String const&, CEGUI::String const&) + 205
7   libCEGUIOpenGLRenderer-0.dylib   0x000000010d88624d CEGUI::OpenGLRendererBase::createTexture(CEGUI::String const&, CEGUI::String const&, CEGUI::String const&) + 317
8   libCEGUIBase-0.dylib             0x000000010d4a6b19 CEGUI::ImageManager::elementImagesetStart(CEGUI::XMLAttributes const&) + 1913
9   libCEGUIExpatParser.dylib        0x000000010d8cccac CEGUI::ExpatParser::startElement(void*, char const*, char const**) + 492
10  libexpat.dylib                   0x000000010da7ce32 doContent + 2066
11  libexpat.dylib                   0x000000010da7ac43 prologProcessor + 10275
12  libexpat.dylib                   0x000000010da77a9a XML_Parse + 330
13  libCEGUIExpatParser.dylib        0x000000010d8cbaa7 CEGUI::ExpatParser::parseXML(CEGUI::XMLHandler&, CEGUI::RawDataContainer const&, CEGUI::String const&) + 119
14  libCEGUIBase-0.dylib             0x000000010d510d9c CEGUI::XMLParser::parseXMLFile(CEGUI::XMLHandler&, CEGUI::String const&, CEGUI::String const&, CEGUI::String const&) + 588
15  libCEGUIBase-0.dylib             0x000000010d4c5286 CEGUI::Scheme::loadResources() + 182
16                                   0x000000010d2d89ad CEGUI::NamedXMLResourceManager<CEGUI::Scheme, CEGUI::Scheme_xmlHandler>::doExistingObjectAction(CEGUI::String, CEGUI::Scheme*, CEGUI::XMLResourceExistsAction) + 2253
17                                   0x000000010d2d6280 CEGUI::NamedXMLResourceManager<CEGUI::Scheme, CEGUI::Scheme_xmlHandler>::createFromFile(CEGUI::String const&, CEGUI::String const&, CEGUI::XMLResourceExistsAction) + 176
18                                   0x000000010d2d5936 initCEGUI() + 3238
19                                   0x000000010d2d66be main + 62
20  libdyld.dylib                    0x00007fff5f97f145 start + 1


Return to “Help”

Who is online

Users browsing this forum: No registered users and 24 guests