我在編譯一些老程序時裏面包含了如open、read、write、_exit、getpid等函數。在linux下能夠編譯通過的包含此頭文件的程序,在VC下編譯時出現瞭如下問題
fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory,所以必須把這個頭文件加入到VS2010的頭文件庫裏面,其它的編譯器也是如此,對於VS2010來說只要在你的默認庫文件夾下(我的電腦是C:\Program Files\Microsoft Visual Studio 10.0\VC\include)添加一個unistd.h文件即可,或者直接增加一個unistd.h頭文件其內容如下:
#ifndef _UNISTD_H
#define _UNISTD_H
#include <io.h>
#include <process.h>
#endif /* _UNISTD_H */
這樣 在重新編譯包含unistd.h的程序就能通過了,但是出現警告:warning C4996: 'read': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _read. See online help for details.
1> d:\program files\microsoft visual studio 10.0\vc\include\io.h(313) : 參見“read”的聲明但是出現警告:
直接用_read替代可消除報警。每個報警中,都可以使用 use the ISO C++ conformant name: 中函數替代,就能消除所有報警
出現警告的原因是Visual C++ 2010使用了更加安全的run-time library routines。所以調用舊的函數時會出現警告。