为什么 msys2 上的 mingw64 不能链接 ftd2xx 库

问题描述 投票:0回答:0

我已经在我的 win10 机器上安装了 MSYS2 以及 mingw64,我还从 https://ftdichip.com/drivers/d2xx-drivers/ 下载了适用于 linux 的 D2XX 驱动程序,我已经提取了存档并将 ftd2xx.h进入 C:\msys64\mingw64\include 文件夹和 libftd2xx.a 进入 C:\msys64\mingw64\lib 文件夹,现在我写了一个简单的程序并尝试这个命令来编译代码

gcc eeprom_example.c -o eeprom_example -lftd2xx

但是我得到了这些链接器错误,

gcc eeprom_example.c -o eeprom_example -lftd2xx
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ASIDES~1\AppData\Local\Temp\ccHdJs8k.o:eeprom_example:(.text+0xbc): undefined reference to `__imp_FT_EEPROM_Read'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ASIDES~1\AppData\Local\Temp\ccHdJs8k.o:eeprom_example:(.text+0x205): undefined reference to `__imp_FT_EEPROM_Program'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ASIDES~1\AppData\Local\Temp\ccHdJs8k.o:eeprom_example:(.text+0x26e): undefined reference to `__imp_FT_Open'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ASIDES~1\AppData\Local\Temp\ccHdJs8k.o:eeprom_example:(.text+0x2d9): undefined reference to `__imp_FT_Close'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ASIDES~1\AppData\Local\Temp\ccHdJs8k.o:eeprom_example:(.text+0x34a): undefined reference to `__imp_FT_Close'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ASIDES~1\AppData\Local\Temp\ccHdJs8k.o:eeprom_example:(.text+0x364): undefined reference to `__imp_FT_Close'
collect2.exe: error: ld returned 1 exit status

我做错了什么?

这是我的实际代码

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "ftd2xx.h"

#define EEPROM_SIZE 256

// Function to read EEPROM content
FT_STATUS readEEPROM(FT_HANDLE handle, uint8_t* eepromData, uint32_t eepromSize)
{
  FT_STATUS status;
  DWORD bytesRead;
  char manufacturer[256];
  char manufacturerId[256];
  char description[256];
  char serialNumber[256];

  status = FT_EEPROM_Read(handle, eepromData, eepromSize, manufacturer, manufacturerId, description, serialNumber);

  if (status != FT_OK)
  {
      printf("Failed to read EEPROM: %d\n", status);
      return status;
  }

  printf("EEPROM content:\n");
  for (int i = 0; i < eepromSize; i++)
  {
      printf("Address 0x%02X: 0x%02X\n", i, eepromData[i]);
  }

  return FT_OK;
}

// Function to write EEPROM content
FT_STATUS writeEEPROM(FT_HANDLE handle, uint8_t* eepromData, uint32_t eepromSize)
{
  FT_STATUS status;
  DWORD bytesWritten;
// Example usage of FT_EEPROM_Program
  char manufacturer[] = "Manufacturer";
  char manufacturerId[] = "ManufacturerId";
  char description[] = "Description";
  char serialNumber[] = "SerialNumber";

  status = FT_EEPROM_Program(handle, eepromData, eepromSize, manufacturer, manufacturerId, description, serialNumber);
  if (status != FT_OK)
  {
      printf("Failed to write EEPROM: %d\n", status);
      return status;
  }

  printf("EEPROM content written successfully!\n");

  return FT_OK;
}

int main()
{
  FT_STATUS status;
  FT_HANDLE handle;
  uint8_t eepromData[EEPROM_SIZE];

  // Initialize and open the FTDI device
  status = FT_Open(0, &handle);
  if (status != FT_OK)
  {
      printf("Failed to open FTDI device: %d\n", status);
      return 1;
  }

  // Read EEPROM content
  status = readEEPROM(handle, eepromData, EEPROM_SIZE);
  if (status != FT_OK)
  {
      FT_Close(handle);
      return 1;
  }

  // Modify EEPROM content (example: set all bytes to 0xFF)
  for (int i = 0; i < EEPROM_SIZE; i++)
  {
      eepromData[i] = 0xFF;
  }

  // Write EEPROM content
  status = writeEEPROM(handle, eepromData, EEPROM_SIZE);
  if (status != FT_OK)
  {
      FT_Close(handle);
      return 1;
  }

  // Close the FTDI device
  FT_Close(handle);

  return 0;
}

c msys2 ftdi d2xx
© www.soinside.com 2019 - 2024. All rights reserved.