0

I am trying to compile a project in Visual studio using Qt plug-in and QCustomPlot library. The code works perfectly fine in QT creator but when I migrate the code to Visual Studio (which I need to use for unrelated reasons) I get this linking error:

Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class QSharedPointer > __cdecl QCPStatisticalBox::data(void)const " (__imp_?data@QCPStatisticalBox@@QEBA?AV?$QSharedPointer@V?$QCPDataContainer@VQCPStatisticalBoxData@@@@@@XZ) referenced in function "public: void __cdecl mop_OUT::addord(double,char)" (?addord@mop_OUT@@QEAAXND@Z)

Please note: This is NOT an issue of failing to link against a lib file or dll that contains the definition. The QCustomPlot library package comes with no such files, only a header file (qcustomplot.h) and a source file (qcustomplot.cpp).

Furthermore, the missing symbol seems to already have an in-line definition in line 5673 of qcustomplot.h:

QSharedPointer<QCPStatisticalBoxDataContainer> data() const { return mDataContainer; }

Does anyone have any ideas as to what my be going on?

Tommy Orok
  • 31
  • 5
  • Are you aware of the [`__declspec`](https://learn.microsoft.com/en-us/cpp/build/exporting-from-a-dll-using-declspec-dllexport?view=vs-2019) meaning? The configuration of `__declspec` is often done by "macro magic". (Examples in Q/A [SO: Static member variable not global between executable and dll](https://stackoverflow.com/a/50228234/7478597) and [SO: GetProcAddress vs __declspec( dllimport )](https://stackoverflow.com/a/52341759/7478597)). AFAIK, Qt uses a similar "macro magic" as well. I would assume that there is a missing define (`/D`) in the command line where the DLL is built. – Scheff's Cat May 07 '19 at 06:53
  • I don't know QT Creator (except by name) but I'm sure it somewhere shows compile command lines. (Every IDE I know does this.) Have a look at command lines in QT Creator which arguments are actually given to build DLL. (If it's `g++` look for `-D`, for MSVC it could be `/D` instead.) Check whether your VS project uses the same defines. (There might be unrelated defines to your issue - if you feel lost, you could extend your question resp. to get help.) – Scheff's Cat May 07 '19 at 06:58
  • May be, it's better to delete your other question. Although, I would like to mention that the [duplicate](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) addresses (among others) the issue I suspected in my previous comments: [Incorrectly importing/exporting methods/classes across modules/dll (compiler specific).](https://stackoverflow.com/a/12574423/7478597) – Scheff's Cat May 07 '19 at 07:06

2 Answers2

0

Properties->Configuration Properties->Liker->Input->Additional Dependencice" add “Qt5PrintSupportd.lib” it works

lowbee
  • 1
0

So i had the same linking error when i tried to use QCustomPlot in visual studio and for me it worked when i right click on Project name (in Solution Explorer), then QT Project Settings, then QT module and select Print Support.

gollerxd
  • 1
  • 1