C++ Visual Studio上的交叉编译错误

C++ Visual Studio上的交叉编译错误,c++,linux,windows,visual-studio,C++,Linux,Windows,Visual Studio,下面是一个函数的快照,我正在使用VisualStudio将它移植到我的Windows机器上 bool MinidumpFileWriter::Open(const char *path) { assert(file_ == -1); #if __linux__ file_ = sys_open(path, O_WRONLY | O_CREAT | O_EXCL, 0600); #else file_ = open(path, O_WRONLY | O_CREAT | O_EXCL,

下面是一个函数的快照,我正在使用VisualStudio将它移植到我的Windows机器上

bool MinidumpFileWriter::Open(const char *path) {
  assert(file_ == -1);
#if __linux__
  file_ = sys_open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
#else
  file_ = open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
#endif

  return file_ != -1;
}
目前,这在我的Linux机器上运行良好。现在,当我尝试将其移植到Windows计算机时,如下所示:

bool MinidumpFileWriter::Open(const char *path) {
  assert(file_ == -1);
#if __linux__
  file_ = sys_open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
  return file_ != -1;
#elif _Win32
  HANDLE hFile;
  hFile = CreateFile(path,               // file to open
                     GENERIC_READ,          // open for reading
                     FILE_SHARE_READ,       // share for reading
                     NULL,                  // default security
                     OPEN_EXISTING,         // existing file only
                     FILE_ATTRIBUTE_NORMAL, // normal file
                     NULL);     
  if (hFile == INVALID_HANDLE_VALUE){ 
      return false; 
  }
  else{
      return true;
  }
#else
  file_ = open(path, O_WRONLY | O_CREAT | O_EXCL, 0600);
  return file_ != -1;
#endif  
}
“#else”宏中的
open
函数给我一个无法识别的错误。根据我对操作系统宏的理解,VisualStudio不应该担心指令中的内容,而只编译代码的Windows部分。但事情并非如此。为什么会这样?

我认为您在Windows中的宏有“case”问题,应该是WIN32或WINNT,请检查

您可能还需要检查以下各项:


它们在移植代码时非常方便

你是如何找到这个名字的?在我的MSVC参考资料中,我只看到
\u WIN32
。是的,我知道了。问题在于宏。另一方面,您链接到的函数已被弃用。