之前的cocos2dx项目在Xcode9.0运行的时候报错了,说是system这个函数不能使用,然后去github上看官方的解决,需要改CCFileUtils.cpp这个文件
首先找到对应的部分,搜索#include
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
#include
#endif
在这下面这个方法下面添加如下代码:
bool FileUtils::createDirectory(const std::string& path){
...
}
namespace
{
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
int rv = remove(fpath);
if (rv)
perror(fpath);
return rv;
}
#endif
}
然后紧挨着的下面,有一个方法,叫做:
bool FileUtils::removeDirectory(const std::string& path)
在方法的开始部分,添加下面内容:
#if !defined(CC_TARGET_OS_TVOS)
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
if (nftw(path.c_str(), unlink_cb, 64, FTW_DEPTH | FTW_PHYS) == -1)
return false;
else
return true;
#else
方法结尾处添加下面内容:
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
#else
return false;
#endif // !defined(CC_TARGET_OS_TVOS)
解决问题,应该官方在下个版本就搞定这个问题了。