Failure to compile “hello world” web server app with Poco

孤者浪人 提交于 2019-12-12 02:56:19

问题


When I search Google for "poco web server example", the very first link it offers me is this one. Now admittedly it has a zero star rating, and Google offers a more official example from Poco one step down the list. Nonetheless, the example is tantalisingly simple, so I tried to add it to an existing (MFC) project and compile it. When I do, I get these errors:

[...]serverapplication.h(215): error C3646: '_serviceStatus': unknown override specifier
[...]serverapplication.h(215): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
[...]serverapplication.h(216): error C3646: '_serviceStatusHandle': unknown override specifier
[...]serverapplication.h(216): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

The errors occur on these two lines in serverapplication.h:

static SERVICE_STATUS        _serviceStatus; 
static SERVICE_STATUS_HANDLE _serviceStatusHandle; 

Naturally, the errors persist even when all I do is include the Poco header files and nothing else... so it's not as if my code has a problem, it's more that my environment has a problem. Indeed, I get precisely the same errors if I replace the list of 8 Poco header files + 3 STL headers with the longer list from Poco's own HTTPTimeServer example (which compiles and runs fine as an independent project by the way).

It looks like SERVICE_STATUS and SERVICE_STATUS_HANDLE are being #defined to nothing at all. Is there a compiler setting or preprocessor definition that would do this? What is the trap that Poco users should beware of falling into? Are there compatibility issues between Poco and MFC?

Update: I can reproduce the issue independently of my application by downloading this zipped project referenced by this potentially relevant article... which builds fine... but the moment I try to specify the extra include folder and include serverapplication.h, these errors occur. There is no mention of any dependencies on the Poco ServerApplication class documentation page.


回答1:


SERVICE_STATUS is a structure defined in the Windows SDK.

The SERVICE_STATUS structure documentation indicates to

include Windows.h

Have you tried to #include <Windows.h>?

Edit
Since you're trying to add it to an MFC application, have you tried to add #include "stdafx.h"?




回答2:


To include POCO's ServerApplication.h header file in an MFC project, try #include <winsvc.h> prior to #include "ServerApplication.h". Note that you must not include Windows.h in an MFC project, which would normally include winsvc.h.



来源:https://stackoverflow.com/questions/35353592/failure-to-compile-hello-world-web-server-app-with-poco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!