UPDATE: A support person with FTDI reached out to me, and confirms their static library can only be used with Microsoft’s compiler. It will not work with GCC, etc. That is the root of my issue. My next question is going to be: Can I do C code with Visual Studio? More to come…
This should be a simple problem to solve, and this problem may be related to using the wrong compiler (a very old Clang 3.3).
FTDI provides device drivers for things like RS232 interfaces. FTDI drivers typically come with Windows, Linux and Mac. When writing a program to use the FTDI device, they provide header files, DLLs and .libs. These come in a .zip file:
Inside this zip are two header files. One is for the common FTDI stuff (Open, Close, etc.). The second is for the FT4222 which is a USB-to-I2C chipset.
Both are provided as .libs for DLLs, or static libraries. They also provide 32-bit and 64-bit versions of each.
Header files:
\LibFT4222-v1.4.7\imports\ftd2xx
\LibFT4222-v1.4.7\imports\LibFT4222\inc
64-bit static libraries:
\LibFT4222-v1.4.7\imports\ftd2xx\lib\amd64
\LibFT4222-v1.4.7\imports\LibFT4222\lib\ucrt\amd64
The files I am using in my test project are:
LibTest.c
ftd2xx.h
LibFT4222.h
ftd2xx.lib (681 KB, 64-bit static library)
LibFT4222-64.lib (12,918 KB, 64-bit static library)
There are defines for each of the libraries that are supposed to be set before including the corresponding header file:
#define FTD2XX_STATIC
#define FT4222_STATIC
#ifndef FTD2XX_STATIC
#error FTD2XX_STATICmust be defined to use static libs.
#endif
#ifndef FT4222_STATIC
#error FT4222_STATIC must be defined to use static libs.
#endif
…though I would normally set it in my project settings.
This “should” be simple, but on LabWindows/CVI 2017 (which uses Clang 3.3), it has a two sets of linker errors to some Windows library stuff that I do not know how to resolve.
When I make a project in Code::Blocks which uses GCC, I only get one set of six mangled references.
GCC errors:
..\..\LibFT4222-v1.4.7\imports\ftd2xx\lib\amd64\ftd2xx.lib(x64\Release\FTD2XX.obj):(.text$mn+0xec)||undefined reference to `??3@YAXPEAX_K@Z'|
..\..\LibFT4222-v1.4.7\imports\ftd2xx\lib\amd64\ftd2xx.lib(x64\Release\FTD2XX.obj):(.text$mn+0x16d)||undefined reference to `??3@YAXPEAX_K@Z'|
..\..\LibFT4222-v1.4.7\imports\ftd2xx\lib\amd64\ftd2xx.lib(x64\Release\FTD2XX.obj):(.text$mn+0x1e5)||undefined reference to `??3@YAXPEAX_K@Z'|
..\..\LibFT4222-v1.4.7\imports\ftd2xx\lib\amd64\ftd2xx.lib(x64\Release\FTD2XX.obj):(.text$mn+0x25d)||undefined reference to `??3@YAXPEAX_K@Z'|
..\..\LibFT4222-v1.4.7\imports\ftd2xx\lib\amd64\ftd2xx.lib(x64\Release\FTD2XX.obj):(.text$mn+0x2d5)||undefined reference to `??3@YAXPEAX_K@Z'|
..\..\LibFT4222-v1.4.7\imports\ftd2xx\lib\amd64\ftd2xx.lib(x64\Release\fteepd.obj):(.data$r+0x0)||undefined reference to `??_7type_info@@6B@'|
||error: ld returned 1 exit status|
||=== Build failed: 7 error(s), 20 warning(s) (0 minute(s), 1 second(s)) ===|
Since GCC gets further, I am going to try to use it.
This sample project is just a test to link to Open and Close functions in the FTD2XX library. Nothing is being used in the FT4222 library, so it really is not part of this test, but ultimately I will need it.
My test program is:
#define FTD2XX_STATIC
#define FT4222_STATIC
// -lsetupapi -ladvapi32 -luser32
#ifndef FT4222_STATIC
#error FT4222_STATIC must be defined to use static libs.
#endif
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "ftd2xx.h" // Add to include path.
#include "LibFT4222.h" // Add to include path.
int main (void)
{
FT_STATUS ftStatus = 0;
FT_HANDLE ftHandle;
ftStatus = FT_OpenEx ((void*)"PrecisePower A",
FT_OPEN_BY_DESCRIPTION,
&ftHandle);
if (FT_OK == ftStatus)
{
FT_Close (ftHandle);
}
return 0;
}
I am posting this to my blog in case someone else is searching for a solution for this.
Meanwhile, if you think you know how to get this to work, please let me know.
IMPORTANT INFO: The FTDI readme says it works in Visual Studio. They have one example they provide that does static linking and it builds just fine. I have not tested it to see if it actually works, and do not know how to tell if it truly is using the static libraries. (We have always used the DLL version of the libraries, and those work fine.)
Is is possible they made a library that will not work in Clang or GCC, but does work in Microsoft’s compiler?
Tips appreciate.