使用 GetProcessTimes 和 FileTimeToSystemTime 的 CPU 处理时间在 64 位 win 中不起作用

发布于 2024-09-06 04:34:07 字数 577 浏览 6 评论 0原文

我正在尝试测量 CPU 时间。 它在 Win 32 上工作得很好,但在 64 位上,它说:

error LNK2019: unresolved external symbol __imp_GetProcessTimes referenced in function "unsigned int __cdecl getWINTime(void)" (?getWIN32Time@@YAIXZ) 

它有类似的错误 FileTimeToSystemTime

error LNK2019: unresolved external symbol __imp_FileTimeToSystemTime referenced in function "unsigned int __cdecl getWINTime(void)" (?getWIN32Time@@YAIXZ)

函数本身并不那么重要,没有问题。
这个调用在 64 位架构中合法吗?

这并不是唯一的问题,它似乎没有正确链接到 64 位 Windows 上的库。
我是否应该设置一个设置才能正确链接?

I am trying to measure CPU time.
It works great on Win 32, but on 64 bit, it says:

error LNK2019: unresolved external symbol __imp_GetProcessTimes referenced in function "unsigned int __cdecl getWINTime(void)" (?getWIN32Time@@YAIXZ) 

It has similar error for FileTimeToSystemTime

error LNK2019: unresolved external symbol __imp_FileTimeToSystemTime referenced in function "unsigned int __cdecl getWINTime(void)" (?getWIN32Time@@YAIXZ)

Function itself is not that important there is no issue with it.
Are this calls legit in 64 bit architecture or what?

This is not the only issue it seems like its not linking correctly to libraries on 64 bit windows.
Is there a setting I should set for it to link properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

长伴 2024-09-13 04:34:07

您为两个环境构建的设置是否列出了相同的导入库。这两个函数都位于 kernel32.dll 中。

Do you're build settings for the two environments have the same import libraries listed. Both of those functions are in kernel32.dll.

看轻我的陪伴 2024-09-13 04:34:07

检查您的链接器标志。 64 位构建的整个项目配置与 32 位构建的不同。因此,请检查您的项目设置以验证它们是否都链接到相同的库。

还可以通过检查项目设置中的命令行窗格或检查构建日志来检查编译器和链接器是否已正确调用。

我刚刚尝试在 Visual Studio 2010 中创建此代码的 64 位版本,并且运行良好:

#include <Windows.h>

int CALLBACK WinMain(
  __in  HINSTANCE hInstance,
  __in  HINSTANCE hPrevInstance,
  __in  LPSTR lpCmdLine,
  __in  int nCmdShow
) {
  FILETIME ct;
  FILETIME et;
  FILETIME kt;
  FILETIME ut;
  GetProcessTimes(NULL, &ct, &et, &kt, &ut);

  SYSTEMTIME st;
  FileTimeToSystemTime(&ut, &st);

}

我只需创建一个新的 Win32 项目,添加一个 64 位平台并进行编译。我根本没有更改任何项目设置。

Check your linker flags. The entire project configuration for 64-bit builds is different from that of 32-bit builds. So check your project settings to verify that they both link to the same libraries.

Also check that the compiler and linker got invoked correctly, either by checking the Command Line panes in project settings, or by inspecting the build log.

I just tried creating a 64-bit build of this code in Visual Studio 2010, and it worked fine:

#include <Windows.h>

int CALLBACK WinMain(
  __in  HINSTANCE hInstance,
  __in  HINSTANCE hPrevInstance,
  __in  LPSTR lpCmdLine,
  __in  int nCmdShow
) {
  FILETIME ct;
  FILETIME et;
  FILETIME kt;
  FILETIME ut;
  GetProcessTimes(NULL, &ct, &et, &kt, &ut);

  SYSTEMTIME st;
  FileTimeToSystemTime(&ut, &st);

}

I simply created a new Win32 project, added a 64-bit platform, and compiled. I didn't change any project settings at all.

窝囊感情。 2024-09-13 04:34:07

GetProcessTimes 和 FileTimeToSystemTime 的文档将告诉您要包​​含的标头以及要链接到的库文件。但是,Visual Studio 通常会自动为您链接这些内容。
您是否忽略了项目中可能检查的默认库?

The documentation for GetProcessTimes and FileTimeToSystemTime will tell you the headers to include, AND the library file to link to as well. However, Visual studio will usually link those in for you automatically.
Do you have ignore default libraries checked perhaps in your project?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文