Poco PropertyFileConfiguration undefined reference in Qt

currently working on a Qt project and I'd also like to use some aspects of the Poco libraries such as the property file configuration functionality. I got the example in my code from page nine of the documentation here: http://pocoproject.org/slides/180-Configuration.pdf

The problem is when compiling, a couple of rather oddly formatted undefined reference errors appear.

C:\projects\build-InternetofGauges-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\webtunnelhandler.o:-1: In function `ZN16WebTunnelHandler13setConfigFileEv':
C:\projects\InternetofGauges\webtunnelhandler.cpp:41: error: undefined reference to `_imp___ZN4Poco4Util25PropertyFileConfigurationC1ERKSs'
C:\projects\InternetofGauges\webtunnelhandler.cpp:43: error: undefined reference to `_imp___ZNK4Poco4Util21AbstractConfiguration6getIntERKSs'
C:\projects\build-InternetofGauges-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\webtunnelhandler.o:-1: In function `ZN4Poco7AutoPtrINS_4Util25PropertyFileConfigurationEEptEv':
C:\My-Devices-SDK\include\Poco\AutoPtr.h:190: error: undefined reference to `_imp___ZN4Poco20NullPointerExceptionC1Ei'
C:\My-Devices-SDK\include\Poco\AutoPtr.h:190: error: undefined reference to `_imp___ZN4Poco20NullPointerExceptionD1Ev'
collect2.exe:-1: error: error: ld returned 1 exit status

My .pro file

QT += core
QT += network
QT += sql
QT += xml
QT -= gui

CONFIG += c++11

TARGET = InternetofGauges
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

INCLUDEPATH += "C:\\My-Devices-SDK\\include" \
               "C:\\OpenSSL\\MinGW\\include"

LIBS += -L"C:\\My-Devices-SDK\\lib\\" \
            -lPocoUtild \
            -lPocoNetd \
            -lPocoNetSSLd \
            -lPocoFoundationd \
            -lPocoJSONd \
            -lPocoWebTunneld \
            -lPocoXMLd
LIBS += -L"C:\\My-Devices-SDK\\lib\\" \
            -lPocoUtil \
            -lPocoNet \
            -lPocoNetSSL \
            -lPocoFoundation \
            -lPocoJSON \
            -lPocoWebTunnel \
            -lPocoXML
LIBS += -L"C:/OpenSSL/MinGW/lib/"

SOURCES += main.cpp \
    webclient.cpp \
    startuphandler.cpp \
    webtunnelhandler.cpp

DISTFILES += \
    Todo.readme

HEADERS += \
    webclient.h \
    startuphandler.h \
    webtunnelhandler.h

The problem code in question

#include <Poco/Util/PropertyFileConfiguration.h>
#include <Poco/AutoPtr.h>

#include "webtunnelhandler.h"

using Poco::AutoPtr;
using Poco::Util::PropertyFileConfiguration;

/* ... */


void WebTunnelHandler::setConfigFile()
{

  AutoPtr<PropertyFileConfiguration> pConf;
  pConf = new PropertyFileConfiguration("WebTunnelAgent.properties");//Error appears here

  int key1 = pConf->getInt("webtunnel.httpPort");//and also here

  return;
}

Now, I've compiled all the poco libraries with MinGW and Qt is also configured for MinGW and compiles and runs great with other parts of my program. I'm also happily using Qt 5.5.1 with the 3.1.6 Qt Creator. My happiness with Qt unfortunately doesn't help my issues.

I have looked at many a stack overflow question on similar topics, and have attempted to recompile the libraries as well as explicitely include the libraries in the .pro file. I also peeked into the Auto.h file and found that it ends up calling the null pointer exception likely due to the line pConf = new PropertyFileConfiguration("WebTunnelAgent.properties"); getting angry at me.

What are the causes of this error? And how does one fix this error?

Answers


Linking order of libraries matters and that has nothing to do with Poco:

the linker searches and processes libraries and object files in the order they are specified. Thus, 'foo.o -lz bar.o' searches library 'z' after file foo.o but before bar.o. If bar.o refers to functions in 'z', those functions may not be loaded.


Okay so I did manage to fix it. I realized that the order of libraries does in fact matter as there are some dependencies between libraries in this case. I also had to add another windows specific library to make it work. Here's the section of the .pro file that worked

LIBS += -L"C:\\My-Devices-SDK\\lib\\" \
            -lPocoUtild \
            -lPocoNetd \
            -lPocoNetSSLd \
            -lPocoXMLd \
            -lPocoJSONd \
            -lPocoWebTunneld \
            -lPocoFoundationd

LIBS += -L"C:\\My-Devices-SDK\\lib\\" \
            -lPocoUtil \
            -lPocoNet \
            -lPocoNetSSL \
            -lPocoXML \
            -lPocoJSON \
            -lPocoWebTunnel \
            -lPocoFoundation

LIBS += -L"C:/OpenSSL/MinGW/lib/"

win32:LIBS += -lIphlpapi

As I said above, Iphlpapi is needed as well as that poco order. Hope this helps someone eventually!


Need Your Help

qn error in JOIN operation

sql ms-access

I've a query that I can't run in Access because it's giving an Error in JOIN Operation.