1

I am trying to get libqglviewer to work in visual studio, I have installed Qt5.2.0 64-bit for VS 2012.

I have added the include directories for QGLViewer and QT in the project settings together with the lib-directory and the lib-files for qt (both Release and Debug).

I have a simple example code to test it:

main.cpp
#include "simpleViewer.h"
#include <qapplication.h>

int main(int argc, char** argv)
{
 // Read command lines arguments.
 QApplication application(argc,argv);

 // Instantiate the viewer.
 /* Viewer viewer;


 viewer.setWindowTitle("simpleViewer");


// Make the viewer window visible on screen.
 viewer.show();

// Run main loop.
 return application.exec();*/
}


simpleViewer.h
#include <QGLViewer/qglviewer.h>

class Viewer : public QGLViewer
{
protected :
virtual void draw();
virtual void init();
virtual QString helpString() const;
};

When I try to compile it I get

 main.obj : error LNK2001: unresolved external symbol "_declspec(dllimport) public: virtual class QString __cdecl QGLViewer::mouseBindingsString(void)const " (__imp_?mouseBindingsString@QGLViewer@@UEBA?AVQString@@XZ)

Plenty of them. I have looked around, but I cannot understand what the error is.

If I comment out everything except QApplication(argc,argv) it compiles, but if I uncomment Viewer viewer I get a lot of errors. I don't see what is missing since it compiles when I only use QApplication.

It feels like there is something missing with the linking, but I have added all .lib files I can find.

One thing is that if I download the libQGLViewer and run the following

qmake -t vclib QGLViewer.pro -spec win32-msvc2013

and then opens it in Visual Studio 2013 ( I changed today without success) it builds and generates the QGLViewer2.dll files as it should according to the instruction on libQGLViewers homepage. But if I try the simpleViewer example it gives the same problems again.

El_Loco
  • 1,716
  • 4
  • 20
  • 35
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Hans Passant Aug 09 '15 at 20:16
  • I don't really see anything that helps me. – El_Loco Aug 09 '15 at 20:46
  • Looks like Qt specific issue, so not duplicate (of that question, at least). – hyde Aug 10 '15 at 07:10
  • Indeed, I have now tried the same thing on Visual Studio 2013 and it still does not work. – El_Loco Aug 10 '15 at 11:58

4 Answers4

2

Had the same error on QT v5.7. Solved it by adding

QT += widgets

in the .pro file at the top.

TeeMo
  • 31
  • 7
1

Edit:

By re-installing everything qt and qt visual studio add-in again, for some reason the add-in searched for old versions of qt, when that was fixed I could open an example from libQGLViewer and immitate all includes and links I could finally get it to work.

El_Loco
  • 1,716
  • 4
  • 20
  • 35
0

You're getting a linker error. Common causes are: Compiler can't find the .lib file for the dll. You built the program and the dll with a different compiler and the name mangling is making it impossible to find the function in the .lib file.

Try adding he QGLViewer project to your project in QCreator and then right click on yours and choose 'add libary' choose internal and reference QGLviewer, then thy will both compile together avoiding and name mnlging issues and QCreator should take care of the lib paths and all.

Tom Kulaga
  • 138
  • 7
  • Yes, I installed the visual studio qt-plugin and got it correctly this time and open the example project as a qt-project in visual studio and managed to compile it. So I am close to get it to work. – El_Loco Aug 10 '15 at 20:20
0

I've faced the same problem in QT 5.13.1. I was trying to use the QSerialPort, but couldn't achieve to build at all. Finally, solved it by adding serialport to the project file(xxx.pro) like the following:

QT += serialport
Caglayan DOKME
  • 948
  • 8
  • 21