Search code examples
cwindowsgcclinkerftdi

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


I'm trying to compile a sample 64-bit c progam using the ftd2xx lib by FTDI using gcc within cygwin without any success. I always end up in linker errors.

My project contains these file:

  • main.c My Sample Application
  • ftd2xx.h The header of the library
  • ftd2xx.lib Importlibrary
  • ftd2xx64.dll dynamic library 64 bit
  • wintypes.h Wrapper used by ftd2xx.h to include windows.h

This is my main function:

#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;
 }

This is my linker cmd

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

And here is my output

/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$5 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$5 section in /cygdrive/e/jschubert/workspaces/testSimple//ftd2xx.lib(FTD2XX.dll.b)

After reading the article How does the Import Library work? Details? and http://www.mikrocontroller.net/topic/26484 I'm pretty shure that there is a problem with the generated export lib functions. But how do I correct them?


Solution

  • On Cygwin -mcmodel=medium is already default. Adding -Wl,--image-base -Wl,0x10000000 to GCC linker fixed the error.