PDA

View Full Version : Import dll problems



tom0485
23rd May 2010, 11:29
Hi there

I have problems using a dll in my Qt-project. The library is used to control this device (http://emx.net.au/top16dio.htm).

In my .pro file I have inserted the following lines to include the top16.dll and the FTD2XX.dll in the lib directory of my project:


LIBS += -Llib \
-lFTD2XX \
-ltop16


The header file top16.h looks like this


#ifndef TOP16_H
#define TOP16_H

#include <qglobal.h>

class Q_DECL_IMPORT top16
{
public:
top16();
int dllversion();
};


class Top16
{
public:
Top16();
};

#endif // TOP16_H


And the top16.cpp files is this


#include "top16.h"
#include <QDebug>

Top16::Top16()
{
top16 myTop16;
qDebug() << "top16 dll version: " << myTop16.dllversion();
}


When compiling the project it returns those errors:


...top16.cpp:6: undefined reference to `_imp___ZN5top16C1Ev'
...top16.cpp:7: undefined reference to `_imp___ZN5top1610dllversionEv'


I guess it is a problem with the definitions in the header file but I can't figure out what the problem is. Has anyone with more experience including libraries an idea?

Cheers, Tom

squidge
23rd May 2010, 11:36
The library is compiled using different name mangling than your application. Ensure both are compiled with the same compiler and name mangling scheme.

Secondly, are you sure you are linking with a C++ library and not a more common C library?

tom0485
24th May 2010, 04:40
As it is a library that is delivered already compiled, I don't know the compiler settings and the name mangling scheme. There is an example in C# - maybe this gives you more of an idea how to import the library:
http://emx.net.au/top16%20C%20sharp%20example.pdf

And I don't know if it is a C or a C++ library - what would I have to change in my code?

squidge
24th May 2010, 08:16
It seems like an FTDI library to me, which means it would be a plain simple 'C' library. Therefore you would need to use 'extern "C"' to reference the external dependancies in that library.

eg.


extern "C" void someFunction(int);

tom0485
24th May 2010, 08:41
Like this?


class Q_DECL_IMPORT top16
{
public:
top16();

extern "C" int dllversion();
};

Then building the project returns the following:


... error: expected unqualified-id before string constant

I still don't really get how the linker should know which dll to use. Is it over the class name? All the tutorials that I found assume that you built the dll yourself or that you have at least the header file...

squidge
24th May 2010, 13:37
You can't use 'extern "C"' in a C++ class, that's a contradiction, and the compiler will complain. As for the DLL, you need to include the .LIB file with your project.

tom0485
25th May 2010, 04:58
A .lib file is not provided by the company. I think I rather try using the virtual com port to talk to the device. Thanks anyway!

squidge
25th May 2010, 07:47
Ok, but there are applications out there that provide .lib file output by parsing a .dll if the manufacturer doesn't provide a suitable one, but it does depend on the compiler.

An alternative is to use QLibrary to load the DLL at run time.