GNU GCC代码块win32函数未声明

GNU GCC Codeblocks win32 function not declared

本文关键字:函数 未声明 win32 GCC 代码 GNU      更新时间:2024-09-28

这是我的项目(Implot(中库的一段代码:

#ifdef _WIN32
t.S = _mkgmtime(ptm);
...
#ifdef _WIN32
if (gmtime_s(ptm, &t.S) == 0)
...
#ifdef _WIN32
if (localtime_s(ptm, &t.S) == 0)

该项目刚刚从Visual Studio 2019移植到Codeblocks(C++17(。由于某种原因,这无法编译,当我搜索错误时,我在网上找不到任何东西。

error '_mkgmtime' was not declared in this scope
error 'gmtime_s' was not declared in this scope
error 'localtime_s' was not declared in this scope

我知道这些错误是因为缺少函数,很可能是由于缺少包含文件,但这些错误已在Visual Studio 2019中使用,没有对任何源代码进行任何更改,并且在那里运行良好。为什么这不起作用?我该如何解决?

如果您阅读Visual Studio预定义的宏文档,您可以找到编译器特定的宏,这些宏将用于确定您的代码是否由Visual Studio C++编译器生成。

例如_MSC_VER宏,您可以检查它而不是_WIN32

如:

#ifdef _MSC_VER
auto result = gmtime_s(ptm, &t.S);// Visual Studio
#else
auto result = gmtime(ptm);        // Anything else (like e.g. GCC)
#endif
if (result == nullptr) ...