1. 程式人生 > >在VS2010下如何使用標頭檔案unistd.h

在VS2010下如何使用標頭檔案unistd.h

我在編譯一些老程式時裡面包含了如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。所以呼叫舊的函式時會出現警告。