【发布时间】:2011-11-19 15:38:50
【问题描述】:
我已经用 C++、OpenGL 和 OpenAL 开发了一款游戏,我正在尝试将它构建到一个应用程序包中,而不是一个命令行可执行文件中。我从 Relative Paths Not Working in Xcode C++ 复制并粘贴了 main.cpp 文件顶部的代码(也在 App_Prefix.pch 中尝试过),我得到了一些语法错误。我已经用错误注释了代码:
#ifdef __APPLE__
#include "CoreFoundation/CoreFoundation.h"
#endif
// ----------------------------------------------------------------------------
// This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle
#ifdef __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) // Error: expected unqualified-id before 'if'
{
// error!
}
CFRelease(resourcesURL); // error: expected constructor, destructor or type conversion before '(' token
chdir(path); // error: expected constructor, destructor or type conversion before '(' token
std::cout << "Current Path: " << path << std::endl; // error: expected constructor, destructor or type conversion before '<<' token
#endif
他的代码在我看来很好,很多人在他的帖子中感谢他。有什么我做错了吗?我是否应该专门为此代码创建一个文件并先导入它?
【问题讨论】: