关闭

错误:undefined reference to `_imp___ZN12QSqlDatabase17defaultConnectionE'

2225人阅读 评论(0) 收藏 举报
分类:

编译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可置于变量或者函数前,以表示变量或者函数的定义在别的文件中,提示编译器遇到此变量或函数时,在其它模块中寻找其定义

1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:68723次
    • 积分:1130
    • 等级:
    • 排名:千里之外
    • 原创:24篇
    • 转载:89篇
    • 译文:9篇
    • 评论:0条