基于Windows set locale和consoleCP调试代码并使其运行。 获取错误:’未定义引用`GetLocaleInfoEx”

我试图让另一个人制作一些代码来工作。 代码基本上获取用户在var locale_name引入的语言环境。 然后设置其ConsoleCPConsoleOutputCP ; 毕竟,将控制台重置为默认值。

我做了一些修改,但我已经陷入黑点,我不知道如何继续。 我收到两个错误: undefined reference to 'GetLocaleInfoEx'error: 'reset_console' undeclared (first use in this function)

我不知道为什么我得到第一个错误。 第二个错误是由于未定义reset_console 。 我想它应该重置控制台的默认配置,但我不知道它应该为它做什么(我的意思是,我不知道如何恢复设置,我一直在搜索,但我没有做任何事情)。

代码是:

 #include  #include  #include  #include  #include  #include  #include  int main() { wchar_t *locale_name = L"es-ES"; if (_wsetlocale(LC_ALL, locale_name)) { int codepage; int gPrevConsoleCP = GetConsoleCP(); if (gPrevConsoleCP) { // The process is attached to a console. int gPrevConsoleOutputCP = GetConsoleOutputCP(); if (GetLocaleInfoEx(locale_name, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER, (LPWSTR)&codepage, sizeof(codepage) / sizeof(wchar_t))) { if (!codepage) { // The locale doesn't have an ANSI codepage. codepage = GetACP(); } SetConsoleCP(codepage); SetConsoleOutputCP(codepage); atexit(reset_console); } } } return 0; } 

知道如何使这段代码有效吗?