(First off, thanks so much. Stackoverflow has been very helpful to me in the past!)
Okay, so I am currently working on a Command Line Tool written in C++ through Xcode.
I’ve done a dozen or so programs in the past like this and had no problem compiling them inside or outside of Xcode. Usually, I just use the terminal’s g++ line to compile manually, but I have occasionally used Xcode’s release. I am definitely less familiar with doing it through Xcode, however, than I am with g++.
That said, this time I am trying to build a project with the SDL framework as well. It’s my first attempt at any sort of GUI and it is way tougher than I’d imagined. I wanted to be able to compile the project and send a copy of the executable file to my professor to show my progress, but I cannot figure out how to do it.
I don’t think it’s possible to build through g++ because I need to also include the SDL and Cocoa frameworks. (That could be very wrong, and if so, that’s also an option!)
When I Build through Xcode, however, I can successfully open it and run it externally through Terminal. So we’re close. But it is unable to find any of the images that I use.
The SDL definitely works, and I can click where the images should be (and it works) but it just says that it can’t open “images/blahblah.bmp”.
Currently my folder heirarchy is like this:
Project folder contains all my .cpp’s and .h’s as well as a folder titled “images” which contains the images. In all my c++ files, I refer to them as “images/border.bmp” for example. To get that to work, I believe I had to set my working directory to this project folder. So that may have something to do with the problem. I did that through the current Scheme, under “working directory”.
I thought that maybe the images folder wasn’t being included in the build? So I tried adding it to the target.
Under Project, Target (accessed by clicking on my Project in the Navigator) I added the folder to Compile Sources, Link Binaries with Libraries, and Copy Files with no result. I tried each independently as well as together.
So, I’m sure I’m missing something very small and silly; I’ve just never done anything like this before. Gotta learn somehow? But I wasn’t able to find anyone with the same problem online. (also, a lot of my search results are blogs, but I’m currently staying in China and am unable to access many of them. … :-/ )
Thanks so much for any help! Hopefully I’ve been clear enough!
Brief Update:
Interestingly, I turned off custom working directory, and put the images into the standard Working Directory instead(which I’m pretty sure is just next to the executable in either “Debug” or “Release” folder), and it still doesn’t work. It does still work in Xcode though (which tells me i think I have the working directory correct.)
The Mac version of SDL sets the working directory to the application bundle’s parent directory. You’re not creating a Mac application bundle so the operating system can’t find the images. A short term fix would be to open the file SDLMain.m and modify the setupWorkingDirectory: method so the working directory is set to your project folder.
A long term and better fix is to create a Mac application bundle. The easiest way to do this is to use SDL’s Xcode project templates. The SDL project templates don’t work on Xcode 4 so you would have to install Xcode 3.2, create the project in 3.2, and do the rest of your work in Xcode 4. Another way to create a Mac application bundle is to create a Cocoa application and add the SDL framework, SDLMain.h, and SDLMain.m to your project. You also have to remove some files, including the xib file and the main.m file.
The following blog post has tips on working with SDL on Mac OS X:
SDL Tips for Mac OS X