通过 FTDI 使用 cygwin 编译一个使用 ftd2xx.lib 的 c 应用程序

Using cygwin to compile a c application using ftd2xx.lib by FTDI

我正在尝试通过 FTDI 在 cygwin 中使用 gcc 使用 ftd2xx lib 编译示例 64 位 c 程序,但没有成功。我总是以链接器错误告终。

我的项目包含这些文件:

这是我的主要功能:

#include <stdio.h>
#include <windows.h>  // for windows specific keywords in ftd2xx.h
#include "ftd2xx.h"   // Header file for ftd2xx.lib
int main()
{
   FT_HANDLE ft_handle;  // handle to the USB ic
   FT_STATUS ft_status;  // for status report(error,io status etc)

   ft_status = FT_Open(0,&ft_handle); //open a connection

   if(ft_status == FT_OK) //error checking
     {
        printf("\n\n\tConnection with FT 232 successfull\n");
     }
   else
     {
        printf("\n\n\tConnection Failed !");
        printf("\n\tCheck device connection");
     }
    FT_Close(ft_handle);    //Close the connection
    return 0;
 }

这是我的链接器命令

Building target: testSimple.exe
Invoking: Cygwin C Linker
gcc -L/cygdrive/e/jschubert/workspaces/testSimple/ -o "testSimple.exe"  ./main.o   -lftd2xx

这是我的输出

/cygdrive/e/jschubert/workspaces/testSimple//ftd2xx.lib(FTD2XX.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_FT_Open' defined in .idata section in /cygdrive/e/jschubert/workspaces/testSimple//ftd2xx.lib(FTD2XX.dll.b)
/cygdrive/e/jschubert/workspaces/testSimple//ftd2xx.lib(FTD2XX.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_FT_Close' defined in .idata section in /cygdrive/e/jschubert/workspaces/testSimple//ftd2xx.lib(FTD2XX.dll.b)

阅读文章How does the Import Library work? Details? and http://www.mikrocontroller.net/topic/26484后,我很确定生成的导出库函数有问题。但是我该如何纠正它们呢?

在 Cygwin 上,-mcmodel=medium 已经是默认设置。将 -Wl,--image-base -Wl,0x10000000 添加到 GCC 链接器修复了错误。