[英]Cross compiling error on Visual Studio
這是我使用Visual Studio從此處移植到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
函數給出了一個無法識別的錯誤。 根據我對操作系統宏的理解,Visual Studio不應該擔心指令內部的內容,只編譯Windows部分代碼。 但事情並非如此。 為什么?
我認為你的Windows中的宏有一個“案例”問題,它應該是_WIN32或WINNT,請點擊此處 。
您可能還想檢查以下內容:
http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx
在移植代碼時它們很方便。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.