0
\$\begingroup\$

Can I create relative filepaths to images in an XCode SDL project?

I have to use absolute filepaths as it is, but it would be much easier if I could make the filepaths relative.

\$\endgroup\$
  • 1
    \$\begingroup\$ Relative paths work fine. You're probably having a problem where the working directory is not what you expect. Check Xcode's working directory settings. \$\endgroup\$ – congusbongus Mar 25 '14 at 2:17
1
\$\begingroup\$

Changing the working directory worked for me recently:

Go to Product -> Scheme -> Edit Scheme.

Then click Run on the left hand panel and then finally enter the path of the files under Working Directory.

All of your paths are then relative to the path you entered.

\$\endgroup\$
0
\$\begingroup\$

you could place your files in a folder called resources or whatever you want it to be at the same directory as the exe. For the file path when using a SDL_LoadBMP() or whatnot will be resources/name_of_image.bmp

\$\endgroup\$
  • 2
    \$\begingroup\$ You could improve this post easily with some formatting and maybe a little extra explanation to the resources folder. Is it automatically referenced as a resource directory? Does the OP need to create any ties to it or is it a relative string he uses that goes relative to his exe? Explain a little further. \$\endgroup\$ – Tom 'Blue' Piddock Mar 28 '14 at 9:46
0
\$\begingroup\$

XCode usually runs your project from an internal directory used for development. One easy way to get the path to your program is to query NSBundle.

NSString * filename = @"images/my_image.jpg";

NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
NSString * fullPath = [filename stringByAppendingPathComponent:filePath];

// fullPath is now the absolute path to the file.

You didn't specify the language, but if you are using C++, you can still use Objective-C inside a .mm file, in the same project.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.