Working fine on OS X :)

Working fine on OS X :)

Postby Knitter » 19 Jan 2012, 00:09

Just reporting that Me & My Shadow works fine under OS X.

Had some trouble with compiling under 64bit since CMake was finding some mixed up libraries but managed to sort things out, recommend that anyone trying to compile the game uses macports to install all the needed dependencies.

I had SDL, SDL_Image and SDL_TTF installed as 32bit frameworks and linking was failing so I removed them forcing CMake to detect the 64bit version installed by macports, all runs fine and I was able to play the tutorial.

Will try to test a bit more and if someone can tell me how to package this thing I can probably provide a binary for download, just need to figure out what to put in a DMG file :?

Edit:
Could someone, please, delete the duplicate post? Don't know how I managed to post the same thing twice...
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: Working fine on OS X :)

Postby Edward_Lii » 19 Jan 2012, 07:06

Hello Knitter,

Knitter {l Wrote}:Just reporting that Me & My Shadow works fine under OS X.

Had some trouble with compiling under 64bit since CMake was finding some mixed up libraries but managed to sort things out, recommend that anyone trying to compile the game uses macports to install all the needed dependencies.

I had SDL, SDL_Image and SDL_TTF installed as 32bit frameworks and linking was failing so I removed them forcing CMake to detect the 64bit version installed by macports, all runs fine and I was able to play the tutorial.

That's great, thanks for testing! ;)

Knitter {l Wrote}:Will try to test a bit more and if someone can tell me how to package this thing I can probably provide a binary for download, just need to figure out what to put in a DMG file :?

It would be great if it could be packaged for Mac OS X, but I'm afraid I haven't got a clue how. :|

Knitter {l Wrote}:Edit:
Could someone, please, delete the duplicate post? Don't know how I managed to post the same thing twice...

Done. :)
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Working fine on OS X :)

Postby Knitter » 19 Jan 2012, 12:23

Edward_Lii {l Wrote}:It would be great if it could be packaged for Mac OS X, but I'm afraid I haven't got a clue how. :|


I'm trying to give this a go but I don't know what I'm doing :), it's a pain to try and use CMake when I have little knowledge of how most of these things work. My current problem is how to make sure all libraries are available to the user since the binary is not statically linked. My dependencies are listed as:
{l Code}: {l Select All Code}
/opt/local/lib/libSDL-1.2.0.dylib (compatibility version 12.0.0, current version 12.3.0)
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0)
/opt/local/lib/libSDL_ttf-2.0.0.dylib (compatibility version 11.0.0, current version 11.0.0)
/opt/local/lib/libSDL_image-1.2.0.dylib (compatibility version 9.0.0, current version 9.2.0)
/opt/local/lib/libSDL_mixer-1.2.0.dylib (compatibility version 11.0.0, current version 11.1.0)
/opt/local/lib/libSDL_gfx.13.dylib (compatibility version 23.0.0, current version 23.1.0)
/usr/lib/libcurl.4.dylib (compatibility version 6.0.0, current version 6.1.0)
/usr/lib/libarchive.2.dylib (compatibility version 9.0.0, current version 9.2.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.44.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.63.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.36.0)


I think I can ignore all the Apple frameworks as I believe they will be available to any OS X SL user, how do I tell CMake that SDL and all its friends are to be included in the final binary? Or maybe there is a way to add the frameworks and libraries to the final app file... well, I'll keep looking at it but I don't except much to come out of my small tests :D
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: Working fine on OS X :)

Postby Edward_Lii » 19 Jan 2012, 17:34

Hello Knitter,

Knitter {l Wrote}:m trying to give this a go but I don't know what I'm doing :), it's a pain to try and use CMake when I have little knowledge of how most of these things work. My current problem is how to make sure all libraries are available to the user since the binary is not statically linked. My dependencies are listed as:

It isn't statically linked on purpose, but perhaps you can somehow include the needed libraries in the .dmg?

Knitter {l Wrote}:I think I can ignore all the Apple frameworks as I believe they will be available to any OS X SL user, how do I tell CMake that SDL and all its friends are to be included in the final binary? Or maybe there is a way to add the frameworks and libraries to the final app file...

I don't know that much about CMake either, but I think it's best if the needed libraries are set as dependency of the .dmg file (if such a thing is possible).

Knitter {l Wrote}:well, I'll keep looking at it but I don't except much to come out of my small tests :D

Thanks for your effort, I really appreciate it. :)
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Working fine on OS X :)

Postby Knitter » 19 Jan 2012, 17:51

I've been reading about dmg files and application bundles and I can place the libraries inside the bundle, the current problem is that I need to use the install_name_tool command line tool to change the place where the executable looks for the linked libraries, so that it searches inside the bundle but whenever I execute the tool nothing is changed in the game's executable.

I'll have to see if I can find out why the my changes are being ignored.
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: Working fine on OS X :)

Postby Knitter » 15 Feb 2012, 13:16

So I'm back at this again, got a few hours of nothing to do :).

I made some progress thanks to Auria and am now facing a problem where I can't tell the executable inside the bundle where the "data" folder is located. How does the code search for resources? The bundle structure places all assets in "Resources/data", this path can be expressed as a relative path to the executable like "../Resources/data" but I find no way to let the executable now of this.

I can't give parameters to the executable inside the bundle so I'm at loss on how to proceed.

EDIT:

After some mucking around I found this little piece of code used to determine the application name and path:
{l Code}: {l Select All Code}
//Get the appPath and the exeName.
{
    char s[4096];
    int i,m;
    #ifdef WIN32
    m=GetModuleFileNameA(NULL,s,sizeof(s));
    #else
    m=readlink("/proc/self/exe",s,sizeof(s));
    #endif
    s[m]=0;
    for(i=m-1;i>=0;i--){
        if(s[i]=='/'||s[i]=='\\'){
            s[i]=0;
            break;
        }
    }
appPath=s;
exeName=s+i+1;
}


I'm not really a the C++ developer but I don't think that code is correctly taking into account the fact that there is no /proc on OS X. Before finding that code I was confused to why the getAppPath method would return garbage (uninitialized string pointer). Granted I would never think of using /proc to determine an executable's name and I don't really know at what I'm looking at but isn't that a bug?
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: Working fine on OS X :)

Postby Edward_Lii » 15 Feb 2012, 15:06

Hello Knitter,

Knitter {l Wrote}:I made some progress thanks to Auria and am now facing a problem where I can't tell the executable inside the bundle where the "data" folder is located. How does the code search for resources? The bundle structure places all assets in "Resources/data", this path can be expressed as a relative path to the executable like "../Resources/data" but I find no way to let the executable now of this.

The data folder path for system wide installations is handled by CMake.
By using the -DCMAKE_INSTALL_PREFIX the path can be set with a given prefix:
{l Code}: {l Select All Code}
cmake -DCMAKE_INSTALL_PREFIX=/usr/ .

CMake will create a config.h file which will contain the configured data path:
$CMAKE_INSTALL_PREFIX+share/meandmyshadow/data/
So I'm not sure what the structure is on MacOS X but whatever folder is chosen it will postfix share/meandmyshadow/data/ to it.
Because this code is only used for Linux it didn't really cause any problems, but I think it's important to make this piece work for every platform.

Knitter {l Wrote}:I'm not really a the C++ developer but I don't think that code is correctly taking into account the fact that there is no /proc on OS X. Before finding that code I was confused to why the getAppPath method would return garbage (uninitialized string pointer). Granted I would never think of using /proc to determine an executable's name and I don't really know at what I'm looking at but isn't that a bug?

I haven't written this code but AFAIK it works on most Linux boxes.
But it's no good on non-Windows systems that don't have a /proc. :|

I'm not even sure wherefor the appPath and EXEName is needed?
Perhaps we can remove this code?
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Working fine on OS X :)

Postby Knitter » 15 Feb 2012, 16:11

Ok, I'll play with it some more and see what I can achieve, I'll update this thread when I have good news ;)
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: Working fine on OS X :)

Postby acme_pjz » 15 Feb 2012, 17:52

Edward_Lii {l Wrote}:I'm not even sure wherefor the appPath and EXEName is needed?
Perhaps we can remove this code?


Remove this code?!? :? No, you are kidding... At least under Windows the data path is always the executable path plus "/data/" and the same as Linux test build... So IMHO we need to do now is find the function to get executable path (or app bundle path) under Mac OS X...

[EDIT] OK, after Google I found this function _NSGetExecutablePath() (http://stackoverflow.com/questions/1023 ... c-self-exe)
Last edited by acme_pjz on 15 Feb 2012, 17:56, edited 1 time in total.
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 489
Joined: 10 Dec 2009, 15:32

Re: Working fine on OS X :)

Postby Edward_Lii » 15 Feb 2012, 17:55

Hello acme_pjz,

acme_pjz {l Wrote}:Remove this code?!? :? No, you are kidding... At least under Windows the data path is always the executable path plus "/data/" and the same as Linux test build... So IMHO we need to do now is find the function to get executable path (or app bundle path) under Mac OS X...

Oh, it's used for that. Forgot about it... :oops:
I'll search for a way to do this.

EDIT: Interesting read (1.14):
http://www.faqs.org/faqs/unix-faq/programmer/faq/

If we see it like this, you either run it from the directory itself (./ or ../ will find it).
Or you run it where it's system wide installed. (datapath is defined before compiling config.h).
In case you run the executable from outside the directory it would fail (without knowing the apppath), unless running with --data-dir.

Perhaps it just shouldn't be run outside the directory?
On the other hand this the current system is quite flexible. :think:
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Working fine on OS X :)

Postby Knitter » 27 Mar 2012, 19:22

So, I've been looking at this again and I can't seem to get over the data path search problems. In almost every place when writing OS specific code you only test for MS Windows and assume the only other OS is GNU Linux, and whatever I do I can't seem to be able to add the needed macros so that I can execute specific OS X code.

I've tried using the standard flags for OS detection, namely __APPLE__ and APPLE (CMake version) but it doesn't work and I don't know where to look for the problem.

I was trying to add the _NSGetExecutablePath() but haven't manage to get the compiler to detect that I'm not running a GNU Linux :(.
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: Working fine on OS X :)

Postby Edward_Lii » 27 Mar 2012, 19:30

Hello

Knitter {l Wrote}:So, I've been looking at this again and I can't seem to get over the data path search problems. In almost every place when writing OS specific code you only test for MS Windows and assume the only other OS is GNU Linux, and whatever I do I can't seem to be able to add the needed macros so that I can execute specific OS X code.

I know, sorry, we should changes this to include other OSes as well.

Knitter {l Wrote}:I've tried using the standard flags for OS detection, namely __APPLE__ and APPLE (CMake version) but it doesn't work and I don't know where to look for the problem.

AFAIK you can easily add a MacOS X code by using the following line:
{l Code}: {l Select All Code}
#elif defined __APPLE__

Place it above every #else part (therefor after the Windows specific code).

If that doesn't work we could perhaps use CMake to detect that your running MacOS X and define it so we can use that to preform the #elif. :think:
edit: https://sourceforge.net/apps/mediawiki/predef/index.php?title=Operating_Systems#MacOS
So perhaps __MACH__ works?

Hope this helps.
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Working fine on OS X :)

Postby Knitter » 27 Mar 2012, 21:49

Ok, not it's working. I wasn't writing the preprocessor code right, should have looked at the syntax a bit closer.

I know I should probably provide a patch, but this will serve as way to hear some comments, please keep in mind that I'm not a C++ user and my C is long gone :). I made some juggling with converting C++ string objects to C strings are there any better ways?

At the start of the file, after the Windows specific code:
{l Code}: {l Select All Code}
#elif defined __APPLE__
   uint32_t size = sizeof(s);
        _NSGetExecutablePath(s, &size);
        //make sure the for below keeps working
         m = strlen(s);
#else
//linux code....


A few lines below, while detecting paths:
{l Code}: {l Select All Code}
//Get the dataPath by trying multiple relative locations.
{
   FILE *f;
   string s;
   while(true){
//Right at the start of tge while
#ifdef __APPLE__
             char buff[4096], *copy;
             s = appPath + "/../Resources/data";
             copy = new char [s.size() + 1];
             strcpy(copy, s.c_str());
             realpath(copy, buff);
             //cout << "DEBUG: Testing path: " << buff << endl;
             if(!dataPath.empty()) {
                 dataPath.clear();
             }
             dataPath.append(buff);
                   
             s = dataPath + "/font/knewave.ttf";
             if((f=fopen(s.c_str(),"rb"))!=NULL){
                 fclose(f);
                 //realpath removes trailing /
                 dataPath.append("/");
                 break;
              }
#endif
//Existing code continues...


Conditional includes:
{l Code}: {l Select All Code}
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif


I don't have time to work on this today, I'll post some updates tomorrow morning or at the end of the day.
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: Working fine on OS X :)

Postby Knitter » 28 Mar 2012, 11:54

Here is my first test while creating both and application bundle and a DMG file. I still have to tune some options and maybe create a smaller DMG as this one is not compressed.

http://content.wuala.com/contents/Knitt ... w.dmg?dl=1
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: Working fine on OS X :)

Postby Edward_Lii » 28 Mar 2012, 13:54

Hello Knitter,

Knitter {l Wrote}:Here is my first test while creating both and application bundle and a DMG file. I still have to tune some options and maybe create a smaller DMG as this one is not compressed.

That's great. :D
Sadly I can't test it myself, if you supply a patch we can commit it to svn.
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 770
Joined: 20 Dec 2010, 16:46

Re: Working fine on OS X :)

Postby odamite » 31 Mar 2012, 13:02

Hello Knitter,

Knitter {l Wrote}:Here is my first test while creating both and application bundle and a DMG file. I still have to tune some options and maybe create a smaller DMG as this one is not compressed.

http://content.wuala.com/contents/Knitt ... w.dmg?dl=1

Thank you! It's nice you've created this build for Mac OS X. Unfortunately I don't have Apple computer to test it. Also we have a trailer on YouTube and some guy asked about the Mac version. I linked the guy your .dmg file and he replied:
TeoLizarraldeOliver (the guy on YouTube) {l Wrote}:Thanks! But its not working...my mac software is the Mac Os X 10.6.8...the .dmg mount, but the game doesn't work...

I'm sorry that I can't help you because I haven't got any experience on developing on Mac. I think that this problem has something to do with the OS versions but that's just a guess. I don't know about Mac OS X version compatibility...

Do you need more information about solving this thing? The guy didn't describe the problem quite precisely. Should I ask him for some more information? Hopefully you've got time to look into this problem and I'm sure you can fix it. :D
User avatar
odamite
 
Posts: 166
Joined: 16 Jan 2012, 16:28

Re: Working fine on OS X :)

Postby Knitter » 31 Mar 2012, 14:22

More info is always appreciated. His version is the latest update for Snow Leopard, I built using Lion, though I think I accounted for previous OS X versions.
If you can get more info from him it would help, at least ask if he can run the executable in the terminal, to do that he will need to run the following command from the same folder has where he put the application bundle, or adapt the path:

{l Code}: {l Select All Code}
./MeAndMyShadow.app/Contents/MacOS/meandmyshadow


Running in a terminal will, hopefully, provide more info about what is wrong.
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: Working fine on OS X :)

Postby Knitter » 31 Mar 2012, 15:13

While trying to debug this problem I think CMake is building against version 10.7 of the SDK, meaning only OS X Lion is supported. I'm trying to determine if that is what is happening and see if I can either change what CMake (maybe change the Makefile that is generated) or use the XCode created files to generate the build correctly.
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Who is online

Users browsing this forum: No registered users and 1 guest