解决方法:
unistd.h 是一个在 Unix 和类 Unix 系统(如 Linux 和 macOS)中常见的头文件,它包含了一组 POSIX 标准定义的系统调用接口。想要在windows用需要进行替换。参考方法:
此外,在按照上述替换后,程序代码还可能在运行时出现如下报错:
[build] F:\code\projects\threadSeg_Yolo_RT_vscode\include\common.hpp(94): error C2065: “F_OK”: 未声明的标识符[build] F:\code\projects\threadSeg_Yolo_RT_vscode\include\common.hpp(107): error C3861: “S_ISREG”: 找不到标识符[build] F:\code\projects\threadSeg_Yolo_RT_vscode\include\common.hpp(116): error C3861: “S_ISDIR”: 找不到标识符修改后的代码(其中注释部分为原代码):
// inline bool IsPathExist(const std::string& path)// {// if (access(path.c_str(), 0) == F_OK) {// return true;// }// return false;// }
inline bool IsPathExist(const std::string& path){ if (_access(path.c_str(), 0) != -1) { return true; } return false;}
// inline bool IsFile(const std::string& path)// {// if (!IsPathExist(path)) {// printf("%s:%d %s not exist\n", __FILE__, __LINE__, path.c_str());// return false;// }// struct stat buffer;// return (stat(path.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode));// }
inline bool IsFile(const std::string& path){ if (!IsPathExist(path)) { printf("%s:%d %s not exist\n", __FILE__, __LINE__, path.c_str()); return false; } struct _stat buffer; if (_stat(path.c_str(), &buffer) != 0) { return false; } return ((buffer.st_mode & _S_IFMT) == _S_IFREG);}
// inline bool IsFolder(const std::string& path)// {// if (!IsPathExist(path)) {// return false;// }// struct stat buffer;// return (stat(path.c_str(), &buffer) == 0 && S_ISDIR(buffer.st_mode));// }
inline bool IsFolder(const std::string& path){ if (!IsPathExist(path)) { return false; } struct _stat buffer; if (_stat(path.c_str(), &buffer) != 0) { return false; } return ((buffer.st_mode & _S_IFMT) == _S_IFDIR);}来源:CSDN 原文,首次发布于 2024-06-26。