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

时间:2018-06-04 10:06:18

标签: c++ qt linker qmake qimage

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

  

错误:未定义引用' QImage :: QImage(int,int,QImage :: Format)'

     

错误:未定义引用' QImage :: isNull()const'

     

错误:未定义引用' QImage :: fill(unsigned int)'

     

错误:未定义引用' QImage :: setPixel(int,int,unsigned int)'

     

错误:未定义引用' QImage :: save(QString const&,char const *,int)

     

错误:未定义引用' QImage :: ~QImage()'

     

错误:未定义引用' QImage :: ~QImage()'

所以问题是我可以将QImage用于静态构建库吗?

在.pro文件中我有:

  

TEMPLATE = lib

     

CONFIG + = staticlib

     

QT + = gui

编辑:我正在使用GCC 4.9编译器为Android,如果使用MSVC2015 for Windows编译错误看起来像:

  

-1:错误:LNK2019:未解析的外部符号" __ declspec(dllimport)public:__ thishisall QImage :: QImage(int,int,enum QImage :: Format)" (__imp _ ?? 0QImage @@ @ QAE @ HHW4Format 0 @@ Z)

     

-1:错误:LNK2019:未解析的外部符号" __ declspec(dllimport)public:virtual __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)

等等。

1 个答案:

答案 0 :(得分:1)

The static library that you have created is not linked to Qt. It's just a collection of object files. The executable this static library is bound to has to be linked to Qt - and that Qt must be a static build in your case.