【问题标题】:Poco PropertyFileConfiguration undefined reference in QtQt 中的 Poco PropertyFileConfiguration 未定义引用
【发布时间】:2026-01-16 05:15:01
【问题描述】:

目前正在处理一个 Qt 项目,我还想使用 Poco 库的某些方面,例如属性文件配置功能。我从这里的文档的第 9 页得到了我的代码中的示例: http://pocoproject.org/slides/180-Configuration.pdf

问题是在编译时,会出现一些格式很奇怪的未定义引用错误。

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

我的 .pro 文件

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

有问题的问题代码

#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;
}

现在,我已经用 MinGW 编译了所有 poco 库,并且 Qt 也为 MinGW 配置了,并且可以很好地与我的程序的其他部分一起编译和运行。我也很高兴将 Qt 5.5.1 与 3.1.6 Qt Creator 一起使用。不幸的是,我对 Qt 的满意并没有解决我的问题。

我查看了许多关于类似主题的堆栈溢出问题,并尝试重新编译库以及将库明确包含在 .pro 文件中。我还查看了 Auto.h 文件,发现它最终调用了空指针异常,可能是因为 pConf = new PropertyFileConfiguration("WebTunnelAgent.properties"); 对我生气。

这个错误的原因是什么?以及如何解决此错误?

【问题讨论】:

    标签: c++ qt reference undefined poco-libraries


    【解决方案1】:

    matters的链接顺序与Poco无关:

    链接器在 它们被指定的顺序。因此,“foo.o -lz bar.o”搜索库 'z' 在文件 foo.o 之后但在 bar.o 之前。如果 bar.o 指的是函数 在“z”中,这些函数可能无法加载。

    【讨论】:

    • 没错!对不起那个。老实说,我不知道为什么我指定 Poco 库与一般库。我已经编辑了答案以反映这一点。
    【解决方案2】:

    好的,所以我确实设法解决了它。我意识到库的顺序实际上很重要,因为在这种情况下库之间存在一些依赖关系。我还必须添加另一个特定于 Windows 的库才能使其工作。这是 .pro 文件中有效的部分

    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
    

    正如我上面所说,需要 Iphlpapi 以及 poco 订单。希望这最终对某人有所帮助!

    【讨论】:

      最近更新 更多