将API从Linux移植到Visual Studio 2008 [英] Porting time APIs from Linux to Visual Studio 2008
问题描述
我有一个应用程序,我移植到Microsoft Visual Studio 2008在Linux上构建和运行良好。
I have an application that I am porting to Microsoft Visual Studio 2008 that builds and runs fine on Linux.
我遇到麻烦的时间例程,我的Linux代码如下所示:
I am having trouble with the time routines, my Linux code looks like this:
#include <sys/types.h>
#include <sys/time.h>
typedef long long Usec;
inline Usec timevalToUsec(const timeval &tv)
{
return (((Usec) tv.tv_sec) * 1000000) + ((Usec) tv.tv_usec);
}
但是编译器在 sys / h
头文件:
fatal error C1083: Cannot open include file:
'sys/time.h': No such file or directory
如果我将include更改为 time.h
我得到一个不同的错误与timeval未定义:
If I change the include to just time.h
I get a different error with timeval not being defined:
error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
这是由于 timeval
未定义。
包括 time.h
sys / time.h
正确,如果是这样,我在Microsoft Visual Studio中得到 struct timeval
的定义2008
Is including time.h
instead of sys/time.h
correct, and if so, where do I get the definition of struct timeval
in Microsoft Visual Studio 2008?
推荐答案
winsock2.h
a href =http://msdn.microsoft.com/en-us/library/windows/desktop/ms740560%28v=vs.85%29.aspx =nofollow> struct timeval
,因为它用于 select
。
The winsock2.h
header fill will pull in struct timeval
since it's used in calls like select
.
这篇关于将API从Linux移植到Visual Studio 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!