VS2012 Linking issue
-
Good day,
I created a vs2012 c++ dll project (no Qt at all) on win7 x64 and I want to use Qt 5.4.1 library in the project. I've downloaded Qt and built it under visual studio 2012 and setup my environment variables following this link
And I used the following line in the VS2012 command prompt to compile the library with no examples.
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -nomake examples -nomake testsOn my dll project, I linked the libraries (static and dynamic) Qt\5.4.1\qtbase\lib and included the headers Qt\5.4.1\qtbase\include
but when I try to use Qt classes like QFile in my code, I got the following error:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QByteArray::~QByteArray(void)" (__imp_??1QByteArray@@QAE@XZ) referenced in function
Any hint?
Thanks in advance!Massi
-
Good day,
I created a vs2012 c++ dll project (no Qt at all) on win7 x64 and I want to use Qt 5.4.1 library in the project. I've downloaded Qt and built it under visual studio 2012 and setup my environment variables following this link
And I used the following line in the VS2012 command prompt to compile the library with no examples.
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -nomake examples -nomake testsOn my dll project, I linked the libraries (static and dynamic) Qt\5.4.1\qtbase\lib and included the headers Qt\5.4.1\qtbase\include
but when I try to use Qt classes like QFile in my code, I got the following error:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QByteArray::~QByteArray(void)" (__imp_??1QByteArray@@QAE@XZ) referenced in function
Any hint?
Thanks in advance!Massi
-
@Massi Why do you build Qt by yourself?
It is much easier to use the Qt Online Installer.
Do you have to use Qt 5.4.1? It is not the latest version.
Do you link your app against libQtCore library?@jsulm Many thanks for your reply, This will solve the problem if I add the following libraries in the Additional Dependencies (right click the solution->properties->Linker->Input->Addiotional Dependencies)
Qt5Cored.lib Qt5Guid.lib Qt5Widgetsd.lib
(I'm building in debug mode)
But when I try to inherit my own class from QWidget with the Q_OBJECT macro in it and build the solution, I got the following error:
error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SynopticsWidget::metaObject(void)const "Same kind of issue. Which library Q_OBJECT come from? I don't have MetaObject.lib
Again Thanks!
Massi
-
@jsulm Many thanks for your reply, This will solve the problem if I add the following libraries in the Additional Dependencies (right click the solution->properties->Linker->Input->Addiotional Dependencies)
Qt5Cored.lib Qt5Guid.lib Qt5Widgetsd.lib
(I'm building in debug mode)
But when I try to inherit my own class from QWidget with the Q_OBJECT macro in it and build the solution, I got the following error:
error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SynopticsWidget::metaObject(void)const "Same kind of issue. Which library Q_OBJECT come from? I don't have MetaObject.lib
Again Thanks!
Massi
@Massi Qt has a tool named moc (meta object compiler). This tool generates code for all classes derived from QObject. This generated code needs to be compiled as well. Please read http://doc.qt.io/qt-5.8/moc.html. When using QtCreator/qmake you usually do not have to care about it as it is done for you. Not sure how to do it with Visual Studio. There is a Qt plug-in for Visual Studio which should make your life easier - do you use it?
-
@jsulm I have installed the plugging in vs2012 and it resulted by adding a Qt5 tab my vs2012 menu bar but I'm not using it.
My project was not created as a Qt project. It was already created as a simple dll long time ago and I just want to use Qt library for some graphic displays. Does my dll need to be a QtProject?1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SynopticsWidget::metaObject(void)const " (?metaObject@SynopticsWidget@@UBEPBUQMetaObject@@XZ) 1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall SynopticsWidget::qt_metacast(char const *)" (?qt_metacast@SynopticsWidget@@UAEPAXPBD@Z) 1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall SynopticsWidget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@SynopticsWidget@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
I'm stuck on that.
Best,Massi
-
@jsulm I have installed the plugging in vs2012 and it resulted by adding a Qt5 tab my vs2012 menu bar but I'm not using it.
My project was not created as a Qt project. It was already created as a simple dll long time ago and I just want to use Qt library for some graphic displays. Does my dll need to be a QtProject?1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SynopticsWidget::metaObject(void)const " (?metaObject@SynopticsWidget@@UBEPBUQMetaObject@@XZ) 1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall SynopticsWidget::qt_metacast(char const *)" (?qt_metacast@SynopticsWidget@@UAEPAXPBD@Z) 1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall SynopticsWidget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@SynopticsWidget@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
I'm stuck on that.
Best,Massi
@Massi If you don't use the plugin and qmake then you will need to handle moc by yourself.
Please read the link I posted before: http://doc.qt.io/qt-5.8/moc.html
There you can even find examples how to do it with make files. -
@Massi If you don't use the plugin and qmake then you will need to handle moc by yourself.
Please read the link I posted before: http://doc.qt.io/qt-5.8/moc.html
There you can even find examples how to do it with make files.@jsulm Many Thanks! Finally it works! I had to handle moc by myself. However I also had to include the moc_Myfile.cpp files in to the solution and change its property Precompiled Header (right click to the project->Properties->C/C++->Precompiled Headers) to Not Using Precompiled Headers
Thanks in advance!
Massi