Suger Mike的博客

梦想有多大,世界就有多大

错误:undefined reference to `_imp___ZN12QSqlDatabase17defaultConnectionE'

编译QT程序因为调用了数据库,编译时每次都出现一下错误:

./tmp\obj\release_shared\main.o:main.cpp:(.text+0x6a): undefined reference to `_imp___ZN12QSqlDatabase17defaultConnectionE'

./tmp\obj\release_shared\main.o:main.cpp:(.text+0xac): undefined reference to `_imp___ZN12QSqlDatabase11addDatabaseERK7QStringS2_'

./tmp\obj\release_shared\main.o:main.cpp:(.text+0xf3): undefined reference to `_imp___ZN12QSqlDatabase15setDatabaseNameERK7QString'

./tmp\obj\release_shared\main.o:main.cpp:(.text+0x10d): undefined reference to `_imp___ZN12QSqlDatabase4openEv'

./tmp\obj\release_shared\main.o:main.cpp:(.text+0x235): undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'

./tmp\obj\release_shared\main.o:main.cpp:(.text+0x378): undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'

./tmp\obj\release_shared\main.o:main.cpp:(.text+0x3c3): undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x3ed): undefined reference to `_imp___ZN12QSqlDatabaseC1Ev'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x412): undefined reference to `_imp___ZN9QSqlQueryC1ERK7QString12QSqlDatabase'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x42c): undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x459): undefined reference to `_imp___ZN9QSqlQuery4execERK7QString'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x46f): undefined reference to `_imp___ZN9QSqlQuery4nextEv'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x49b): undefined reference to `_imp___ZNK9QSqlQuery5valueEi'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x4ce): undefined reference to `_imp___ZNK9QSqlQuery5valueEi'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x64b): undefined reference to `_imp___ZN9QSqlQueryD1Ev'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x73e): undefined reference to `_imp___ZN9QSqlQuery4nextEv'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x7d1): undefined reference to `_imp___ZN9QSqlQueryD1Ev'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x8fb): undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'

./tmp\obj\release_shared\dialog.o:dialog.cpp:(.text+0x91a): undefined reference to `_imp___ZN9QSqlQueryD1Ev'

字面上的原因大致是没有定义数据库类,遇见这种问题,大多是在工程文件中没有添加SQL

解决方案:在xxx.pro文件中添加一句QT+=sql


备注:extern可置于变量或者函数前,以表示变量或者函数的定义在别的文件中,提示编译器遇到此变量或函数时,在其它模块中寻找其定义

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liuligui5200/article/details/46776637
个人分类: 问题集萃
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

错误:undefined reference to `_imp___ZN12QSqlDatabase17defaultConnectionE'

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭