qt程序运行时的错误?undefined reference to `_imp___ZN10QTcpSocketD1Ev'

本文解决了使用QT网络模块时遇到的链接错误问题,并提供了在.pro文件中添加QT网络依赖的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


出现的错误为:
undefined reference to `_imp___ZN10QTcpSocketD1Ev'
undefined reference to `_imp___ZN10QTcpSocketC1EP7QObject'
undefined reference to `_imp___ZN10QTcpSocketD1Ev'
undefined reference to `_imp___ZN10QTcpSocketD1Ev'
undefined reference to `_imp___ZN10QTcpSocketD1Ev'
undefined reference to `_imp___ZN10QTcpSocketD1Ev'
undefined reference to `_imp___ZN10QTcpSocketD1Ev'
undefined reference to `_imp___ZN15QAbstractSocket13connectToHostERK7QStringt6QFlagsIN9QIODevice12OpenModeFlagEE'
undefined reference to `_imp___ZN15QAbstractSocket5closeEv'

collect2: ld returned 1 exit status

解决方案:
貌似链接错误。检查.pro文件中是否缺少
 QT += network
[ 91%] Linking CXX shared library G:\czg\ewbvision\ewb_ai_20250506-001\EWB_AI_VISION\Plugins\libSerialPort.dll CMakeFiles\SerialPort.dir/objects.a(mocs_compilation.cpp.obj): In function `SerialPort::metaObject() const': G:/czg/ewbvision/ewb_ai_20250506-001/EWB_AIMachineVisionInspection/build/Desktop_Qt_5_15_0_MinGW_64_bit-Debug/SerialPort/SerialPort_autogen/EWIEGA46WW/moc_SerialPort.cpp:79: undefined reference to `__imp__ZN10SerialPort16staticMetaObjectE' CMakeFiles\SerialPort.dir/objects.a(mocs_compilation.cpp.obj): In function `qt_plugin_instance': G:/czg/ewbvision/ewb_ai_20250506-001/EWB_AIMachineVisionInspection/build/Desktop_Qt_5_15_0_MinGW_64_bit-Debug/SerialPort/SerialPort_autogen/EWIEGA46WW/moc_SerialPort.cpp:116: undefined reference to `__imp__ZN10SerialPortC1Ev' CMakeFiles\SerialPort.dir/objects.a(mocs_compilation.cpp.obj): In function `__static_initialization_and_destruction_0': G:/czg/ewbvision/ewb_ai_20250506-001/EWB_AIMachineVisionInspection/build/Desktop_Qt_5_15_0_MinGW_64_bit-Debug/SerialPort/SerialPort_autogen/EWIEGA46WW/moc_SerialPort.cpp:68: undefined reference to `__imp__ZN10SerialPort16staticMetaObjectE' CMakeFiles\SerialPort.dir/objects.a(SerialPort.cpp.obj): In function `SerialPort::SerialPort()': G:/czg/ewbvision/ewb_ai_20250507/EWB_AIMachineVisionInspection/SerialPort/SerialPort.cpp:4: undefined reference to `__imp__ZTV10SerialPort' G:/czg/ewbvision/ewb_ai_20250507/EWB_AIMachineVisionInspection/SerialPort/SerialPort.cpp:4: undefined reference to `__imp__ZTV10SerialPort' collect2.exe: error: ld returned 1 exit status mingw32-make.exe[3]: *** [SerialPort\CMakeFiles\SerialPort.dir\build.make:187: G:/czg/ewbvision/ewb_ai_20250506-001/EWB_AI_VISION/Plugins/libSerialPort.dll] Error 1 mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:1204: SerialPort/CMakeFiles/SerialPort.dir/all] Error 2 mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:1211: SerialPort/CMakeFiles/SerialPort.dir/rule] Error 2 mingw32-make.exe: *** [Makefile:519: SerialPort] Error 2 09:20:08: 进程"C:\cmake-4.0.0-windows-x86_64\bin\cmake.exe"退出,退出代码 2 。 09:20:08: Error while building/deploying project EWB (kit: Desktop Qt 5.15.0 MinGW 64-bit) 09:20:08: When executing step "构建" 这个错误的原因是什么
05-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值