Results 1 to 12 of 12

Thread: Reference an external C dll

  1. #1
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Reference an external C dll

    Hello,

    I am trying to reference an external C dll in my project, but I get some errors:

    undefined reference to '_imp__FT_Open@8'
    undefined reference to '_imp__FT_GetDeviceInfo@24'
    undefined reference to '_imp__FT_Close@4'

    In my .pro file I put:

    LIBS += -L"lib/"
    qtAddLibrary(ftd2xx)

    The .dll and .h files are available from FTDI, to communicate with USB chip.

    My project is in the attachments.

    Anyone can help me?

    Thanks.
    Attached Files Attached Files

  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference an external C dll

    Please ignore this post (even though it does work) - see post from ChrisW67 for correct solution

    ================================================
    I'm using the same device, the following works for me:

    Inside the .pro file:

    Qt Code:
    1. INCLUDEPATH += c:/ftdidrv
    2. ...
    3. LIBS += c:/ftdidrv/i386/libftd2xx.a
    To copy to clipboard, switch view to plain text mode 

    btw: I created libftd2xx.a (perhaps a bit of a misnomer) as follows:

    reimp -d ftd2xx.lib
    This will create a file called FTD2XX.DEF, which then needs the leading underscore removed from all function names. Next issue the following command:

    dlltool --input-def FTD2XX.def --dllname ftd2xx.dll --output-lib libftd2xx.a -k

    your app will still need the dll, and I redistribute the one click FTDI CDM installer with my app. I just realized this will only work for i386 -

    If you find a better way, I'd be quite interested

    ps: reimp is part of mingw-utils. Download version 0.3, not 0.4.1 (this one didn't work for me)
    Last edited by schnitzel; 22nd February 2011 at 23:25. Reason: correction

  3. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reference an external C dll

    Are you sure your lib is compiled with the same compiler you use?

    In example Visual C++ and GCC?
    A camel can go 14 days without drink,
    I can't!!!

  4. #4
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference an external C dll

    Quote Originally Posted by mcosta View Post
    Are you sure your lib is compiled with the same compiler you use?

    In example Visual C++ and GCC?
    that's exactly what reimp is for.

  5. #5
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Reference an external C dll

    I already used the reimp, but the errors are same

    I dont know what to do

  6. #6
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference an external C dll

    Quote Originally Posted by newtoncw View Post
    I already used the reimp, but the errors are same

    I dont know what to do
    did you follow the steps in my earlier post exactly?
    Did you download and run the CDM installer?

  7. #7
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Reference an external C dll

    Quote Originally Posted by schnitzel View Post
    did you follow the steps in my earlier post exactly?
    Did you download and run the CDM installer?
    Yes, I follow your steps and I follow the FTDI's installation guide, but I still get the same errors

    Can you send me your dlls with the .a files? Or your test project?
    My e-mail is newtoncw@hotmail.com

    Thanks for your help

  8. #8
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference an external C dll

    if you get the exact same error then you did not follow this step:

    This will create a file called FTD2XX.DEF, which then needs the leading underscore removed from all function names
    can you attach your project again?

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,641
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Reference an external C dll

    Given that the interface is declared ' extern "C" ' and the functions are not __stdcall there should not be any name mangling issues and no need for the reimp/dlltool stuff.

    I don't know what "qtAddLibrary()" is: cannot find it in my docs. Your PRO file should look like this:
    Qt Code:
    1. LIBS += -L$$quote($$PWD/lib) -lftd2xx
    To copy to clipboard, switch view to plain text mode 
    and you do not need either the .def file or the resulting .a file. With just ftd2xx.dll and ftd2xx.lib in the lib directory this works just fine:
    Qt Code:
    1. Y:\testeusb>dir /b lib
    2. ftd2xx.dll
    3. ftd2xx.lib
    4.  
    5. Y:\testeusb>qmake "CONFIG+=release"
    6.  
    7. Y:\testeusb>mingw32-make
    8. mingw32-make -f Makefile.Release
    9. mingw32-make[1]: Entering directory `Y:/testeusb'
    10. g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT
    11. -DQT_DLL -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"c:\Qt\2010.02.1\qt\i
    12. nclude\QtCore" -I"c:\Qt\2010.02.1\qt\include" -I"c:\Qt\2010.02.1\qt\include\Acti
    13. veQt" -I"release" -I"c:\Qt\2010.02.1\qt\mkspecs\win32-g++" -o release\main.o mai
    14. n.cpp
    15. g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
    16. oc -Wl,-s -Wl,-subsystem,console -mthreads -Wl -o release\testeusb.exe release/m
    17. ain.o -L"c:\Qt\2010.02.1\qt\lib" -LY:/testeusb/lib -lftd2xx -lQtCore4
    18. mingw32-make[1]: Leaving directory `Y:/testeusb'
    19.  
    20. Y:\testeusb>dir /b release
    21. main.o
    22. testeusb.exe
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 23rd February 2011 at 02:29.

  10. #10
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference an external C dll

    @ChrisW67 you're right - I just did a rebuild of my app. I'm not sure why I went down that road of using reimp - I guess I was trying to create a static lib and failed as it still required the dll. I then just left it at that.
    Last edited by schnitzel; 22nd February 2011 at 22:55. Reason: reworded

  11. #11
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Reference an external C dll

    Thanks @schnitzel, I really had forgotten that step

    @ChrisW67, this works fine

    Now its all ok

    Thanks guys

  12. #12
    Join Date
    Sep 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference an external C dll

    I am sorry to revive this thread .. but the thing is that i have the same symptoms, but not the same solution...

    I also get this error when compiling:

    C:\...\testeusb\main.cpp:22: error: undefined reference to `_imp__FT_Open@8'

    Even though i modified the .pro file with that line:

    Qt Code:
    1. LIBS += -L$$quote($$PWD/lib) -lftd2xx
    To copy to clipboard, switch view to plain text mode 

    FYI, I downloaded the project file inlcuded in this thread, so i am assuming something is wrong with my compiler..? (since all user here seem to be able to compile it..)

    I am using QT 4.8.1 with mingw.

    Thank you very much.

Similar Threads

  1. Reference to ui
    By Phalanx in forum Qt Programming
    Replies: 7
    Last Post: 22nd April 2010, 15:58
  2. undefined reference
    By jayreddy in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2009, 13:45
  3. Undefined reference to crt
    By derektaprell in forum Installation and Deployment
    Replies: 0
    Last Post: 20th October 2009, 08:34
  4. Reference to a class
    By Gayathri in forum Qt Programming
    Replies: 3
    Last Post: 18th December 2006, 14:27
  5. reference problem
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2006, 12:13

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.