code_junkie

Relative Paths Not Working in Xcode C++

Nov 14th, 2011
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. sound->LoadMusic( (std::string) "Resources/Audio/Pop.wav" );
  2.  
  3. std::cout << "Current directory is: " << getcwd( buffer, 1000) << "n";
  4.  
  5. #ifdef __APPLE__
  6. #include "CoreFoundation/CoreFoundation.h"
  7. #endif
  8.  
  9. // ----------------------------------------------------------------------------
  10. // This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle
  11. #ifdef __APPLE__
  12. CFBundleRef mainBundle = CFBundleGetMainBundle();
  13. CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
  14. char path[PATH_MAX];
  15. if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
  16. {
  17. // error!
  18. }
  19. CFRelease(resourcesURL);
  20.  
  21. chdir(path);
  22. std::cout << "Current Path: " << path << std::endl;
  23. #endif
  24. // ----------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment