QtService (QtSolutions) static linking
-
Hi,
I am trying to use QtService in my project but I run into problems. I use Visual Studio 2015 on Windows 10 and Qt 5.8.
I want to link statically so apparently the preferred method is including the code of QtService directly into my VS project.
The linker says that there are unresolved external symbols. This is apparently due to qtservice.cpp not being compiled even if it is part of the VS project. Has anybody already encountered this?
Thanks in advance1>MyService.obj : error LNK2019: unresolved external symbol "public: __thiscall QtServiceBase::QtServiceBase(int,char * *,class QString const &)" (??0QtServiceBase@@QAE@HPAPADABVQString@@@Z) referenced in function "public: __thiscall MyService::MyService(int,char * *)" (??0MyService@@QAE@HPAPAD@Z) 1>MyService.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall QtServiceBase::~QtServiceBase(void)" (??1QtServiceBase@@UAE@XZ) referenced in function __unwindfunclet$??0MyService@@QAE@HPAPAD@Z$1 1>main.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall QtServiceBase::~QtServiceBase(void)" (??1QtServiceBase@@UAE@XZ) 1>MyService.obj : error LNK2019: unresolved external symbol "public: void __thiscall QtServiceBase::setServiceDescription(class QString const &)" (?setServiceDescription@QtServiceBase@@QAEXABVQString@@@Z) referenced in function "public: __thiscall MyService::MyService(int,char * *)" (??0MyService@@QAE@HPAPAD@Z) 1>MyService.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QtServiceBase::stop(void)" (?stop@QtServiceBase@@MAEXXZ) 1>MyService.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QtServiceBase::pause(void)" (?pause@QtServiceBase@@MAEXXZ) 1>MyService.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QtServiceBase::resume(void)" (?resume@QtServiceBase@@MAEXXZ) 1>MyService.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QtServiceBase::processCommand(int)" (?processCommand@QtServiceBase@@MAEXH@Z) 1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall QtServiceBase::exec(void)" (?exec@QtServiceBase@@QAEHXZ) referenced in function _main
-
You are right, this is not static linking, what I mean is that I don't want to dynamically link to a DLL.
QtServiceBase is declared in qtservice.h and most of its methods (e.g. constructor and destructor) are defined in qtservice.cpp. These are two of the methods which the linker cannot find. What I cannot understand is why the compiler is not compiling qtservice.cpp, since this is part of the project.
Right-clicking on qtservice.cpp and choosing "compile" results in the following message:1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): warning MSB8018: No outputs specified for item "src\qtservice\src\qtservice.cpp". Its custom build command will be skipped.
But even after searching online I am not totally sure what that means in my case. Any help is appreciated.
Here is the link to the code of QtService:
https://github.com/qtproject/qt-solutions/tree/master/qtservice/src -
I just click on "include in project" in the solution explorer in VS, that always causes the .cpp file to be compiled.
I now separated all declarations and definitions, creating a .h file and a .cpp file for each class. For some reason that works but of course it is not optimal...