QtCharts causing linking errors (LNK2019)
-
Hi, I've been trying to use QtCharts for Qt 5.7 for VS 2013, 32 bit. However, whenever I try to use a QtChart object, for example QHorizontalStackedBarSeries, it results in numerous linking errors. Here is an example of a cpp file where this occurs:
#include <qtcharts/qchartview> #include <qtcharts/qbarseries> #include <qtcharts/qbarset> #include <qtcharts/qlegend> #include <qtcharts/qbarcategoryaxis> #include <qtcharts/qhorizontalstackedbarseries> using namespace std; using namespace QtCharts; ClassName::ClassName() { } ClassName::FunctionName() { QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries(); }
This results in the following errors:
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QtCharts::QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(class QObject *)" (__imp_??0QHorizontalStackedBarSeries@QtCharts@@QAE@PAVQObject@@@Z) referenced in function "public: __thiscall ClassName::FunctionName(class QWidget *)" (??0ClassName@@QAE@PAVQWidget@@@Z) ProjectName\ClassName.obj ProjectName Error 3 error MSB6006: "link.exe" exited with code 1120. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets 607 5 ProjectName Error 4 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QtCharts::QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries(void)" (__imp_??1QHorizontalStackedBarSeries@QtCharts@@UAE@XZ) referenced in function "public: virtual void * __thiscall QtCharts::QHorizontalStackedBarSeries::`scalar deleting destructor'(unsigned int)" (??_GQHorizontalStackedBarSeries@QtCharts@@UAEPAXI@Z) ProjectName\ClassName.obj ProjectName Error 5 error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QtCharts::QHorizontalStackedBarSeries::metaObject(void)const " (?metaObject@QHorizontalStackedBarSeries@QtCharts@@UBEPBUQMetaObject@@XZ) ProjectName\ClassName.obj PrjoectName Error 6 error LNK2001: unresolved external symbol "public: virtual int __thiscall QtCharts::QHorizontalStackedBarSeries::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QHorizontalStackedBarSeries@QtCharts@@UAEHW4Call@QMetaObject@@HPAPAX@Z) ProjectName\ClassName.obj ProjectName Error 7 error LNK2001: unresolved external symbol "public: virtual void * __thiscall QtCharts::QHorizontalStackedBarSeries::qt_metacast(char const *)" (?qt_metacast@QHorizontalStackedBarSeries@QtCharts@@UAEPAXPBD@Z) ProjectName\ClassName.obj ProjectName Error 8 error LNK2001: unresolved external symbol "public: virtual enum QtCharts::QAbstractSeries::SeriesType __thiscall QtCharts::QHorizontalStackedBarSeries::type(void)const " (?type@QHorizontalStackedBarSeries@QtCharts@@UBE?AW4SeriesType@QAbstractSeries@2@XZ) ProjectName\ClassName.obj ProjectName Error 9 error LNK1120: 6 unresolved externals ProjectName\ClassName.obj ProjectName
This will also happen with other QtChart objects, such as QBarSet. Would anyone have an idea what could be causing this? I've already tried:
-cleaning the project
-in QtLauncher, cleaning the project and running QMake
-adding "QT += charts" in the .pro fileAny input would be appreciated, thanks!
-
@ashkan849
Hello,
First a very quick note. These types of includes:#include <qtcharts/qbarcategoryaxis>
will render your program uncompilable on any platform different from windows. My advice is to stick to the standard way of including the headers, i.e. respecting their case.
Now to the main problem, have installed the QtCharts module?Kind regards.
-
Yes I believe you are right, I think you mean that I should have it as:
#include <QtCharts/QBarCategoryAxis>
I have installed Qt 5.7 for VS2013 (32 bit), which includes the source files for QtCharts in the folder <Qt directory>\5.7\msvc2013\include\QtCharts. Is that sufficient?
-
Hi and welcome to devnet,
It should yes. However there's something not clear: did you re-run qmake after adding
QT += charts
? -
Good, then next thing to check: do you have the lib files available ? Should be but doesn't hurt to double check.
-
Yes I believe you are right, I think you mean that I should have it as
Yes, that's what I meant.
I have installed Qt 5.7 for VS2013 (32 bit), which includes the source files for QtCharts in the folder <Qt directory>\5.7\msvc2013\include\QtCharts. Is that sufficient?
I'd be more concerned, just like @SGaist, whether you can find the import library (the .lib) file and the actual binary (the .dll). Could you search for them in the appropriate folders?
-
You guys are on to something. Apparently I forgot to include QtCharts.lib/QtChartsd.lib in Properties -> Linker -> Input -> Additional Dependencies. I then also had to copy the QtCharts.dll and QtChartsd.dll to the release and debug folders respectively, and now my program runs. Thanks so much for your help!
-
Aha ! You're using Visual Studio to build your application… That was the big missing piece of the puzzle…
I took you where using Qt Creator.
You shouldn't need to copy the .dlls since your application already worked before.
In any case, glad you found out.
Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)