Hi everyone,
I've got a ansi-compliant c++ games project using "takes a deep breath" openGL, SDL, cAudio, SDL_image, SDL_ttf which I started developing on Windows and I'm investigating how to get things to work on Mac. I'm on XCode 4.3.2 and I'm on mac osx 10.7.4.
I'm linking my application with the Cocoa framework, am using gcc 4.2 and I am using SDLMain.m and SDLMain.h directly in my project which you can get from the sdl-devel package.
So I've managed to get to the same point in my application on Mac where I was at at windows. The application compiles, links and runs and I can start receiving debug messages from cout etc.
Let's come to the problem. I have created the xcodeproj inside my root where my source code resides:
-- xcodeproj
-- all source files
Data files are one level deeper for instance:
-- enemies/enemy.xml
I then configured xcode to build to my project root / xcodebuild
So I end up with xcodebuild / debug / myapp
When running, my logs tell me that the application can't find my data files such as enemies / enemy.xml
I've heard about bundles and the resources folder and I also saw this little piece of code on a different forum:
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
[[NSFileManager defaultManager] changeCurrentDirectoryPath:resourcePath];
I put this in my SDLMain and it allows me to run my app either from Xcode or from the app directly in the xcodebuild / debug / myapp directory. The above mentioned code should give you the original forum post that is useful to understand how mac's working directories work. My whole app runs fine if I manually copy all of my resource files to the directory where my app resides.
There's fundamentally two issues I am facing with xcode:
Why do I need to add my files to a special build phase in my target? When running my app, why does it not find enemies/enemy.xml? Why can't I add a directory to xcode, and it will automatically copy all the files in that directory to the build directory? I can only select individual files, so everytime I would add another data file, like enemy2.xml, I would have to remember adding it into my copy files build phase. This gets worse, because for each directory like enemies/enemy.xml or weapons/weapon.xml I would have an additional "copy file" build phase.
What is a good approach to cross-platform applications using sdl when they hit the mac platform?
The second issue for me on mac is that I don't fully understand how to deploy my application so that all of my dylib files and frameworks are bundled together and ready to be turned into an (i'm assuming) dmg or pkg file, ready for installation on someone else's system. I'm curious to know how mac people do this and I hope you can point me in the right direction.
Thanks for any insights you might provide
I've got a ansi-compliant c++ games project using "takes a deep breath" openGL, SDL, cAudio, SDL_image, SDL_ttf which I started developing on Windows and I'm investigating how to get things to work on Mac. I'm on XCode 4.3.2 and I'm on mac osx 10.7.4.
I'm linking my application with the Cocoa framework, am using gcc 4.2 and I am using SDLMain.m and SDLMain.h directly in my project which you can get from the sdl-devel package.
So I've managed to get to the same point in my application on Mac where I was at at windows. The application compiles, links and runs and I can start receiving debug messages from cout etc.
Let's come to the problem. I have created the xcodeproj inside my root where my source code resides:
-- xcodeproj
-- all source files
Data files are one level deeper for instance:
-- enemies/enemy.xml
I then configured xcode to build to my project root / xcodebuild
So I end up with xcodebuild / debug / myapp
When running, my logs tell me that the application can't find my data files such as enemies / enemy.xml
I've heard about bundles and the resources folder and I also saw this little piece of code on a different forum:
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
[[NSFileManager defaultManager] changeCurrentDirectoryPath:resourcePath];
I put this in my SDLMain and it allows me to run my app either from Xcode or from the app directly in the xcodebuild / debug / myapp directory. The above mentioned code should give you the original forum post that is useful to understand how mac's working directories work. My whole app runs fine if I manually copy all of my resource files to the directory where my app resides.
There's fundamentally two issues I am facing with xcode:
Why do I need to add my files to a special build phase in my target? When running my app, why does it not find enemies/enemy.xml? Why can't I add a directory to xcode, and it will automatically copy all the files in that directory to the build directory? I can only select individual files, so everytime I would add another data file, like enemy2.xml, I would have to remember adding it into my copy files build phase. This gets worse, because for each directory like enemies/enemy.xml or weapons/weapon.xml I would have an additional "copy file" build phase.
What is a good approach to cross-platform applications using sdl when they hit the mac platform?
The second issue for me on mac is that I don't fully understand how to deploy my application so that all of my dylib files and frameworks are bundled together and ready to be turned into an (i'm assuming) dmg or pkg file, ready for installation on someone else's system. I'm curious to know how mac people do this and I hope you can point me in the right direction.
Thanks for any insights you might provide