Results 1 to 8 of 8

Thread: Import dll problems

  1. #1
    Join Date
    May 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Import dll problems

    Hi there

    I have problems using a dll in my Qt-project. The library is used to control this device.

    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:
    Qt Code:
    1. LIBS += -Llib \
    2. -lFTD2XX \
    3. -ltop16
    To copy to clipboard, switch view to plain text mode 

    The header file top16.h looks like this
    Qt Code:
    1. #ifndef TOP16_H
    2. #define TOP16_H
    3.  
    4. #include <qglobal.h>
    5.  
    6. class Q_DECL_IMPORT top16
    7. {
    8. public:
    9. top16();
    10. int dllversion();
    11. };
    12.  
    13.  
    14. class Top16
    15. {
    16. public:
    17. Top16();
    18. };
    19.  
    20. #endif // TOP16_H
    To copy to clipboard, switch view to plain text mode 

    And the top16.cpp files is this
    Qt Code:
    1. #include "top16.h"
    2. #include <QDebug>
    3.  
    4. Top16::Top16()
    5. {
    6. top16 myTop16;
    7. qDebug() << "top16 dll version: " << myTop16.dllversion();
    8. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Import dll problems

    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?

  3. #3
    Join Date
    May 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Import dll problems

    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?

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Import dll problems

    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.
    Qt Code:
    1. extern "C" void someFunction(int);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    May 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Import dll problems

    Like this?
    Qt Code:
    1. class Q_DECL_IMPORT top16
    2. {
    3. public:
    4. top16();
    5.  
    6. extern "C" int dllversion();
    7. };
    To copy to clipboard, switch view to plain text mode 
    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...

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Import dll problems

    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.

  7. The following user says thank you to squidge for this useful post:

    tom0485 (25th May 2010)

  8. #7
    Join Date
    May 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Import dll problems

    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!

  9. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Import dll problems

    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.

Similar Threads

  1. How do i import and use a DLL like Skype4COM.dll in Qt4?
    By fernando in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2010, 07:22
  2. import pdf file as image
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2008, 06:43
  3. Import PostgreSQL Values to QT
    By raphaelf in forum Newbie
    Replies: 8
    Last Post: 23rd May 2007, 09:09
  4. How to import an old application code ?
    By yellowmat in forum Qt Tools
    Replies: 6
    Last Post: 12th September 2006, 15:27
  5. import library linking
    By bruce1007 in forum Qt Programming
    Replies: 6
    Last Post: 19th May 2006, 10:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.