Advertisement

Using Xcode results in file not found error

Started by August 12, 2017 02:54 AM
3 comments, last by sjhalayka 7 years, 6 months ago

I'm using Xcode on Mac OS X, and I've added a file called 'peacock.tga' into my project. I can't seem to open that file (using fopen) however. Is there anything special that I need to do in order for the file to be readable?

You need to make sure you use the correct path to the file. If you're just creating a regular, console-type application, the .tga is probably not being copied to the output directory of the executable. If you're creating an OS X bundle, you probably want to ensure the .tga is packaged into the bundle and that you use a path to where the file ends up in the Resources subdirectory of the bundle.

Advertisement

If you're porting and building a Mac OSX bundle app, you've have some file handling rework ahead of you. First, I recommend that you add your assets as references rather than directly in the project. This is because XCode will preserve folder structure for referenced folders, while flattening file hierarchies that are directly included in the project. Second, you will need to follow these instructions to get a real file path:

https://stackoverflow.com/questions/8768217/how-can-i-find-the-path-to-a-file-in-an-application-bundle-nsbundle-using-c

You'll be able to use fopen as normal after that. While we're on the topic, I'll point out that this approach will not work on Android, where you have to go through explicit platform-specific IO APIs to load content embedded in your app.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

Thank you for the replies.

I managed to get it working using this code:


	    
    NSString *fileRoot = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"peacock.tga"];
	    tga_32bit_image peacock_img;
    peacock_img.load([fileRoot UTF8String]);
	

This topic is closed to new replies.

Advertisement