Skip to content

Instantly share code, notes, and snippets.

@vbalien
Created December 11, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbalien/2c2e64152009e2d667e8 to your computer and use it in GitHub Desktop.
Save vbalien/2c2e64152009e2d667e8 to your computer and use it in GitHub Desktop.
using compile flag ' -framework CoreFoundation'
#ifdef __APPLE__
#include "CoreFoundation/CoreFoundation.h"
#endif
#include <iostream>
int main() {
#ifdef __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
{
// error!
}
CFRelease(resourcesURL);
chdir(path);
std::cout << "Current Path: " << path << std::endl;
#endif
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment