Windows 套接字和身份验证构建在包含 Poco-Library 时失败
Windows Socket and Authentication build failed when including Poco-Library
我编写了一个C++程序来验证Windows用户,该程序在未包含Poco库(事件)时无缝工作。我有一个无限的while循环(while(true)),当没有来自serer应用程序的请求时需要停止。套接字读取在单独的线程中独立运行。
编译器 : 明W 7.2
C++标准 : C++14
包管理器 : Msys2
架构 : x64
我收到一个错误:
g++ -c -g -D__DEBUG -I/C/msys64/mingw64/include/boost -I/C/msys64/mingw64/include `pkg-config --cflags libconfig++` `pkg-config --cflags gnutls` -std=c++14 -MMD -MP -MF "build/Debug/MinGW-Windows/Authenticate.o.d" -o build/Debug/MinGW-Windows/Authenticate.o Authenticate.cpp
In file included from C:/msys64/mingw64/include/Poco/Foundation.h:102:0,
from C:/msys64/mingw64/include/Poco/Event.h:23,
from Common.hpp:41,
from Authenticate.hpp:19,
from Authenticate.cpp:14:
C:/msys64/mingw64/include/Poco/Platform_WIN32.h:179:92: note: #pragma message: Compiling POCO on Windows without #define POCO_WIN32_UTF8 is deprecated.
#pragma message("Compiling POCO on Windows without #define POCO_WIN32_UTF8 is deprecated.")
^
Authenticate.cpp: In member function 'bool Authenticate::authenticateUserCommandLine(std::__cxx11::string, std::__cxx11::string, std::__cxx11::string, std::__cxx11::string&)':
Authenticate.cpp:30:26: error: 'LogonUser' was not declared in this scope
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), NULL, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
Authenticate.cpp:30:26: note: suggested alternative: 'LogonUserW'
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), NULL, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
LogonUserW
Authenticate.cpp:32:26: error: 'LogonUser' was not declared in this scope
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
Authenticate.cpp:32:26: note: suggested alternative: 'LogonUserW'
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
LogonUserW
Authenticate.cpp: In member function 'bool Authenticate::authenticateUserCommandLine(std::__cxx11::string, std::__cxx11::string, std::__cxx11::string&)':
Authenticate.cpp:54:26: error: 'LogonUser' was not declared in this scope
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), NULL, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
Authenticate.cpp:54:26: note: suggested alternative: 'LogonUserW'
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), NULL, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
LogonUserW
Authenticate.cpp:56:26: error: 'LogonUser' was not declared in this scope
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
Authenticate.cpp:56:26: note: suggested alternative: 'LogonUserW'
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
LogonUserW
如果我删除#include <Poco/Event.h>
程序可以正常工作,没有错误。
如果我添加#define POCO_WIN32_UTF8
,我必须用LogonUserW
替换LogonUser
。我在添加#define POCO_WIN32_UTF8
时遇到的最大问题是我在::GetLastError()
说找不到函数时收到错误。
登录用户使用情况 :
if(password.length() == 0)
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), NULL, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
else
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
::GetLastError() 用法 :
string Error::GetLastErrorAsString(void)
{
//Get the error message, if any.
DWORD errorMessageID = ::GetLastError();
if(errorMessageID == 0)
return string(); //No error message has been recorded
LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
string message(messageBuffer, size);
//Free the buffer.
LocalFree(messageBuffer);
return message;
}
问题是我在windows.h
之前包含了Poco/Event.h
。Poco/Event.h
需要先定义#define POCO_WIN32_UTF8
,然后再包含导致问题的标头。
通过在定义之前包含windows.h
解决了这个问题#define POCO_WIN32_UTF8
而而Poco/Event.h
又在包含之前定义。
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 编译包含字符串的代码时遇到问题
- c++库的公共头文件中应该包含什么
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 将包含C样式数组的对象初始化为成员变量(C++)
- 是否需要删除包含对象的"pair"?
- Boost Graph Library,修复节点大小
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 使用mongocxx驱动程序时包含头文件问题
- 如何在h文件中包含.o对象文件
- 在混合代码库中将C转换为C++时出现许多包含错误
- Windows 套接字和身份验证构建在包含 Poco-Library 时失败
- 将Poco C++库包含到Mac OS X上的Qt Quick应用程序(Qt Creator)中
- 如何在C++中包含MAC中/Library/Framework文件夹中的文件
- 如何准确包含 POCO 库
- 使用POCO电子邮件时每个包含"No such file/directory"
- 如何使用Boost Filesystem Library v3确定文件是否按路径包含
- 使用Poco库-路径名中包含空格时编译错误