【发布时间】: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