我可以在将项目编译为静态库(未定义的引用)时在代码中使用 QImage 吗?

Can I use QImage in my code while I'm compiling my project as static lib (undefined reference)?

本文关键字:代码 QImage 引用 编译 项目 静态 未定义 我可以      更新时间:2023-10-16

我正在Qt Creator中开发项目,我需要在编译为静态lib的类成员函数中绘制图像,没有错误,但是当我尝试使用此函数时,我收到以下错误:

错误:未定义对"QImage::QImage(int, int, QImage::Format("的引用

错误:未定义对"QImage::isNull(( const"的引用

错误:未定义对"QImage::fill(unsigned int("的引用

错误:未定义对"QImage::setPixel(int, int, unsigned int("的引用

error: 未定义对 'QImage::save(QString const&, char const*, int( 的引用

错误:未定义对"QImage::~QImage(("的引用

错误:未定义对"QImage::~QImage(("的引用

所以问题是我可以将QImage与静态构建库一起使用吗?

在 .pro 文件中,我有:

模板 = 库

配置 += 静态库

QT += GUI

已编辑:我使用的是适用于Android的GCC 4.9编译器,如果使用Windows错误的MSVC2015进行编译,如下所示:

-1:错误:LNK2019:未解析的外部符号"__declspec(dllimport( public:__thiscall QImage::QImage(int,int,enum QImage::Format("(__imp_??0QImage@@QAE@HHW4Format@0@@Z(

-1:错误:LNK2019:未解析的外部符号"__declspec(dllimport(公共:虚拟__thiscall QImage::~QImage(void("(__imp_??1QImage@@UAE@XZ(

-1:错误: LNK2019: 未解析的外部符号 "__declspec(dllimport( public: void __thiscall QImage::setPixel(int,int,unsigned int(" (__imp_?setPixel@QImage@@QAEXHHI@Z(

等等。

您创建的静态库未链接到Qt。它只是对象文件的集合。这个静态库绑定到的可执行文件必须链接到Qt - 并且在你的情况下,Qt必须是静态构建。