View Full Version : Reference an external C dll
newtoncw
22nd February 2011, 19:57
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.
schnitzel
22nd February 2011, 20:13
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:
INCLUDEPATH += c:/ftdidrv
...
LIBS += c:/ftdidrv/i386/libftd2xx.a
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 - :eek:
If you find a better way, I'd be quite interested ;)
ps: reimp is part of mingw-utils (http://sourceforge.net/projects/mingw/files/MinGW/Utilities/mingw-utils/). Download version 0.3, not 0.4.1 (this one didn't work for me)
mcosta
22nd February 2011, 20:37
Are you sure your lib is compiled with the same compiler you use?
In example Visual C++ and GCC?
schnitzel
22nd February 2011, 20:40
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.
newtoncw
22nd February 2011, 20:57
I already used the reimp, but the errors are same :(
I dont know what to do
schnitzel
22nd February 2011, 21:08
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?
newtoncw
22nd February 2011, 23:08
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
schnitzel
22nd February 2011, 23:25
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?
ChrisW67
22nd February 2011, 23:35
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:
LIBS += -L$$quote($$PWD/lib) -lftd2xx
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:
Y:\testeusb>dir /b lib
ftd2xx.dll
ftd2xx.lib
Y:\testeusb>qmake "CONFIG+=release"
Y:\testeusb>mingw32-make
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `Y:/testeusb'
g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT
-DQT_DLL -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"c:\Qt\2010.02.1\qt\i
nclude\QtCore" -I"c:\Qt\2010.02.1\qt\include" -I"c:\Qt\2010.02.1\qt\include\Acti
veQt" -I"release" -I"c:\Qt\2010.02.1\qt\mkspecs\win32-g++" -o release\main.o mai
n.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
oc -Wl,-s -Wl,-subsystem,console -mthreads -Wl -o release\testeusb.exe release/m
ain.o -L"c:\Qt\2010.02.1\qt\lib" -LY:/testeusb/lib -lftd2xx -lQtCore4
mingw32-make[1]: Leaving directory `Y:/testeusb'
Y:\testeusb>dir /b release
main.o
testeusb.exe
schnitzel
22nd February 2011, 23:53
@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.
newtoncw
23rd February 2011, 01:13
Thanks @schnitzel, I really had forgotten that step :p
@ChrisW67, this works fine
Now its all ok
Thanks guys :D
ikalogic
23rd September 2012, 12:49
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:
LIBS += -L$$quote($$PWD/lib) -lftd2xx
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.