FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: libMPSSE: gcc returns an error  (Read 752 times)

White_Fox

  • Newbie
  • *
  • Posts: 2
    • View Profile
libMPSSE: gcc returns an error
« on: August 10, 2018, 07:01:30 AM »

Hi

 I try to go first steps with libMPSSE for writing a simple SPI test for a FT232H, using gcc-installed with cygwin-under Netbeans.

Now, the gcc returns: "relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SPI_GetNumChannels'". The message points to the SPI_GetNumChannels()-call in following code (below):

Code: [Select]
/******************************************************************************/
/* Include files    */
/******************************************************************************/
/* Standard C libraries */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/* OS specific libraries */
#define _WIN32
#ifdef _WIN32
#include<windows.h>
#endif

/* Include D2XX header*/
#include "ftd2xx.h"

/* Include libMPSSE header */
#include "libMPSSE_spi.h"

/******************************************************************************/
/* Macro and type defines    */
/******************************************************************************/
/* Helper macros */

#define APP_CHECK_STATUS(exp) {if(exp!=FT_OK){printf("%s:%d:%s(): status(0x%x) \
!= FT_OK\n",__FILE__, __LINE__, __FUNCTION__,exp);exit(1);}else{;}};
#define CHECK_NULL(exp){if(exp==NULL){printf("%s:%d:%s():  NULL expression \
encountered \n",__FILE__, __LINE__, __FUNCTION__);exit(1);}else{;}};

/* Application specific macro definations */
#define SPI_DEVICE_BUFFER_SIZE  256
#define SPI_WRITE_COMPLETION_RETRY  10
#define START_ADDRESS_EEPROM  0x00 /*read/write start address inside the EEPROM*/
#define END_ADDRESS_EEPROM  0x10
#define RETRY_COUNT_EEPROM  10 /* number of retries if read/write fails */
#define CHANNEL_TO_OPEN   0 /*0 for first available channel, 1 for next... */
#define SPI_SLAVE_0    0
#define SPI_SLAVE_1    1
#define SPI_SLAVE_2    2
#define DATA_OFFSET    4
#define USE_WRITEREAD   0

/******************************************************************************/
/* Global variables       */
/******************************************************************************/
static FT_HANDLE ftHandle;
static uint8 buffer[SPI_DEVICE_BUFFER_SIZE] = {0};

int main() {
    FT_STATUS status = FT_OK;
    FT_DEVICE_LIST_INFO_NODE devList = {0};
    ChannelConfig channelConf = {0};
    uint8 address = 0;
    uint32 channels = 0;
    uint16 data = 0;
    uint8 i = 0;
    uint8 latency = 255;

    channelConf.ClockRate = 5000;
    channelConf.LatencyTimer = latency;
    channelConf.configOptions = SPI_CONFIG_OPTION_MODE0 | SPI_CONFIG_OPTION_CS_DBUS3; // | SPI_CONFIG_OPTION_CS_ACTIVELOW;
    channelConf.Pin = 0x00000000; /*FinalVal-FinalDir-InitVal-InitDir (for dir 0=in, 1=out)*/

    /* init library */
#ifdef _MSC_VER
    Init_libMPSSE();
#endif
    status = SPI_GetNumChannels(&channels); //<-- compiler-error here

    //printf("Es sind %u Gerät(e) angeschlossen", channels);

    return (EXIT_SUCCESS);
}

The initialisation is the same like in code samples. I guess that the problem occures cause I'm working with a 64bit-OS (Win7), but I'm not sure about this. Sorry, but my experiance in C is quite poorly, in special of windows programming. The compiled sample programm works fine, but the code samples does not compile.

Does anyone have an idea how I get the code working?

Edit: Here is the complete output from Netbeans:

Quote
cd 'I:\Documents\NetBeansProjects\GettingStartedMPSSE'
C:\cygwin\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/i/Documents/NetBeansProjects/GettingStartedMPSSE'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/gettingstartedmpsse.exe
make[2]: Entering directory '/cygdrive/i/Documents/NetBeansProjects/GettingStartedMPSSE'
mkdir -p dist/Debug/Cygwin-Windows
gcc     -o dist/Debug/Cygwin-Windows/gettingstartedmpsse build/Debug/Cygwin-Windows/main.o
build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/i/Documents/NetBeansProjects/GettingStartedMPSSE/main.c:69: undefined reference to `SPI_GetNumChannels'
/cygdrive/i/Documents/NetBeansProjects/GettingStartedMPSSE/main.c:69:(.text+0x85): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SPI_GetNumChannels'
collect2: error: ld returned 1 exit status
make[2]: *** [nbproject/Makefile-Debug.mk:63: dist/Debug/Cygwin-Windows/gettingstartedmpsse.exe] Error 1
make[2]: Leaving directory '/cygdrive/i/Documents/NetBeansProjects/GettingStartedMPSSE'
make[1]: *** [nbproject/Makefile-Debug.mk:59: .build-conf] Error 2
make[1]: Leaving directory '/cygdrive/i/Documents/NetBeansProjects/GettingStartedMPSSE'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2

BUILD FAILED (exit value 2, total time: 2s)
« Last Edit: August 10, 2018, 08:11:14 AM by White_Fox »
Logged

White_Fox

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: libMPSSE: gcc returns an error
« Reply #1 on: August 13, 2018, 11:51:42 AM »

After several attempts, I got new error messages. The message above does not seems to be triggered by 32/64bit-problem. I appreciated this cause most hints relating to this message suggest this.

I started a new project (now with MinGW) and add the sample-path in libMPSSE "LibMPSSE-SPI\samples\SPI\SPI" to the directory (project property in Netbeans IDE), also the linker path. Headerfiles are included from here.
Now the compiler returns:
Quote
cd 'I:\Documents\NetBeansProjects\GettingStartedMPSSE2'
C:\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/i/Documents/NetBeansProjects/GettingStartedMPSSE2'
"/C/MinGW/msys/1.0/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/gettingstartedmpsse2.exe
make.exe[2]: Entering directory `/i/Documents/NetBeansProjects/GettingStartedMPSSE2'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/main.o.d"
gcc -m32   -c -g -I/I/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI -include /I/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI/WinTypes.h -include /I/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI/ftd2xx.h -include /I/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI/libMPSSE_spi.h -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.c
In file included from <command-line>:32:0:
i:/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI/ftd2xx.h:259:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'FT_Open'
   FT_STATUS WINAPI FT_Open(
                    ^~~~~~~
i:/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI/ftd2xx.h:265:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'FT_OpenEx'
   FT_STATUS WINAPI FT_OpenEx(
                    ^~~~~~~~~
i:/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI/ftd2xx.h:272:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'FT_ListDevices'
   FT_STATUS WINAPI FT_ListDevices(
                    ^~~~~~~~~~~~~~
i:/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI/ftd2xx.h:279:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'FT_Close'
   FT_STATUS WINAPI FT_Close(
                    ^~~~~~~~
i:/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI/ftd2xx.h:284:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'FT_Read'
   FT_STATUS WINAPI FT_Read(
                    ^~~~~~~
i:/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI/ftd2xx.h:292:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'FT_Write'
   FT_STATUS WINAPI FT_Write(
                    ^~~~~~~~
i:/C-Bibliotheken/LibMPSSE-SPI/samples/SPI/SPI/ftd2xx.h:300:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'FT_IoCtl'
   FT_STATUS WINAPI FT_IoCtl(
                    ^~~~~~~~
...more errors, deleted cause post lenght

make.exe[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
make.exe[2]: Leaving directory `/i/Documents/NetBeansProjects/GettingStartedMPSSE2'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/i/Documents/NetBeansProjects/GettingStartedMPSSE2'
make.exe": *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 20s)

The errors are linked to ftd2xx.h. If I follow the error links, I can find that:
Quote
#ifdef __cplusplus //<-- This is line no. 253
extern "C" {
#endif


   FTD2XX_API
      FT_STATUS WINAPI FT_Open( //<- This is red marked, line no. 259
      int deviceNumber,
      FT_HANDLE *pHandle
      );

   FTD2XX_API
      FT_STATUS WINAPI FT_OpenEx( //<- This is red marked, line no. 265
      PVOID pArg1,
      DWORD Flags,
      FT_HANDLE *pHandle
      );

   FTD2XX_API
      FT_STATUS WINAPI FT_ListDevices( //<- This is red marked, line no. 271
      PVOID pArg1,
      PVOID pArg2,
      DWORD Flags
      );

Please, has anyone an idea what is missing or why the build fails? I don't think that there is a '=' missing, but what else is going wrong?
Logged