Pregunta

I am making a SDL project in Xcode and I have a folder called resources where my images are stored. For my SDL application to access these images with SDL_LoadBMP the resources folder needs to be in the same folder as the executable file. I don't want to have to copy and paste my resources into the "/Users/admin/Library/Developer/Xcode/DerivedData/SDL_app-awvygturnguyeqgwpjowmouadbjf/Build/Products/Debug" folder every time I want to run an application (I don't know why all the random characters are in the folder link). I have been following Lazy Foo's first SDL tutorial: http://lazyfoo.net/SDL_tutorials/lesson01/index2.php and I am trying to display an image on the screen. I don't need to show my code in here because it is the exact same as the tutorial I linked to except instead of SDL_LoadBMP("hello.bmp") it is SDL_LoadBMP("resources/images/hello.bmp"). The application works as soon as I copy the resources folder into the product directory. I was going to show an image of the folder and so on but I didn't have enough 'reputation'.

¿Fue útil?

Solución

In order to make sure the folder gets copied, you need to add the folder to your Xcode project and then create a Copy step in your Build Phases. By default, there is a Copy Phase for items that are identified as Resources by the system (.strings files, .xib files, etc.) However, for additional files, you'll need to create a Copy Phase specifically.

To do this:

  1. In Xcode, select your project and Target and choose the Build Phases tab
  2. Click on the Add Build Phase button and choose Add Copy Files
  3. Select the Destination location for the copy (this is the "top" of the hierarchy, you can also specify sub-directories using the Subpath field)
  4. Now drag the folders or files from the Project Navigator into the new Copy Phase

When you build your executable, the files will be copied as you direct them.

If your SDL files are being modified outside of Xcode, you may want to import the folder as a Folder Reference instead of as individual files. This can be a little tricky, but it causes Xcode to copy the current contents of the folder, as opposed to just the items that you've added to the Project. Otherwise, just import the SDL files directly into the Xcode project and manage them individually.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top