0

对于这个特定的文件,我在 Stack Overflow 上没有看到任何内容。我从http://www.ftdichip.com/Drivers/D2XX.htm为 OS X 10.7下载并安装了 FTDI 串行 USB 适配器的驱动程序。现在,我正在尝试从包含的示例中标题为“简单”的文件夹中获取示例代码。我创建了一个新的 XCODE (4.5) 项目并导入了必要的。

我收到以下编译错误:

ld /Users/availableimac/Library/Developer/Xcode/DerivedData/SerialTest-djxlngfrdsbhhdacorrnmcgxxdpc/Build/Products/Debug/SerialTest normal x86_64 cd /Users/availableimac/Documents/HardwareDev/SerialTest setenv MACOSX_DEPLOYMENT_TARGET 10.7 /Applications/Xcode.app/ Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/availableimac /Library/Developer/Xcode/DerivedData/SerialTest-djxlngfrdsbhhdacorrnmcgxxdpc/Build/Products/Debug -F/Users/availableimac/Library/Developer/Xcode/DerivedData/SerialTest-djxlngfrdsbhhdacorrnmcgxxdpc/Build/Products/Debug -filelist /Users/availableimac/Library /Developer/Xcode/DerivedData/SerialTest-djxlngfrdsbhhdacorrnmcgxxdpc/Build/Intermediates/SerialTest。build/Debug/SerialTest.build/Objects-normal/x86_64/SerialTest.LinkFileList -mmacosx-version-min=10.7 -o /Users/availableimac/Library/Developer/Xcode/DerivedData/SerialTest-djxlngfrdsbhhdacorrnmcgxxdpc/Build/Products/Debug/串行测试

架构x86_64的未定义符号:“_FT_Close”,引用自:main.o中的_main“_FT_GetQueueStatus”,引用自:main.o中的_main“_FT_ListDevices”,引用自:main.o中的_main“_FT_OpenEx”,引用自:_main在 main.o “_FT_Read”中,引用自:main.o 中的 _main “_FT_SetBaudRate”,引用自:main.o 中的 _main “_FT_Write”,引用自:main.o 中的 _main ld:未找到体系结构的符号x86_64 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

您可以在此处获取项目文件夹:https ://drive.google.com/file/d/0B602Cy_Ktj0BdUVxZ3JrUVdpZlU/view?usp=sharing

makefile 不是 xCode 项目的一部分。它是原始示例代码的一部分。我不知道如何解决这个问题。我将不胜感激任何帮助!

主.c:

/*
Simple example to open a maximum of 4 devices - write some data then read       it back.
Shows one method of using list devices also.
Assumes the devices have a loopback connector on them and they also have a serial number

To build use the following gcc statement
(assuming you have the d2xx library in the /usr/local/lib directory).
gcc -o simple main.c -L. -lftd2xx -Wl,-rpath /usr/local/lib
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ftd2xx.h"
#define BUF_SIZE 0x10

#define MAX_DEVICES     5

int iDevicesOpen;


static void dumpBuffer(unsigned char *buffer, int elements)
{
  int j;

printf(" [");
for (j = 0; j < elements; j++)
{
    if (j > 0)
        printf(", ");
        printf("0x%02X", (unsigned int)buffer[j]);
    }
    printf("]\n");
}



int main()
{
  unsigned char     cBufWrite[BUF_SIZE];
  unsigned char * pcBufRead = NULL;
  char *    pcBufLD[MAX_DEVICES + 1];
  char  cBufLD[MAX_DEVICES][64];
  DWORD dwRxSize = 0;
  DWORD     dwBytesWritten, dwBytesRead;
  FT_STATUS ftStatus;
  FT_HANDLE ftHandle[MAX_DEVICES];
  int   iNumDevs = 0;
  int   i, j;

  for(i = 0; i < MAX_DEVICES; i++) {
      pcBufLD[i] = cBufLD[i];
  }
  pcBufLD[MAX_DEVICES] = NULL;

  ftStatus = FT_ListDevices(pcBufLD, &iNumDevs, FT_LIST_ALL |      FT_OPEN_BY_SERIAL_NUMBER);

  if(ftStatus != FT_OK) {
      printf("Error: FT_ListDevices(%d)\n", (int)ftStatus);
      return 1;
  }

  for(i = 0; ( (i <MAX_DEVICES) && (i < iNumDevs) ); i++) {
      printf("Device %d Serial Number - %s\n", i, cBufLD[i]);
  }

  for(j = 0; j < BUF_SIZE; j++) {
      cBufWrite[j] = j;
  }

  for(i = 0; ( (i <MAX_DEVICES) && (i < iNumDevs) ) ; i++) {
      /* Setup */
      if((ftStatus = FT_OpenEx(cBufLD[i], FT_OPEN_BY_SERIAL_NUMBER, &ftHandle[i])) != FT_OK){
        /*
         This can fail if the ftdi_sio driver is loaded
         use lsmod to check this and rmmod ftdi_sio to remove
         also rmmod usbserial
         */
        printf("Error FT_OpenEx(%d), device %d\n", (int)ftStatus, i);
        printf("Use lsmod to check if ftdi_sio (and usbserial) are present.\n");
        printf("If so, unload them using rmmod, as they conflict with ftd2xx.\n");
        return 1;
    }

    printf("Opened device %s\n", cBufLD[i]);

    iDevicesOpen++;
    if((ftStatus = FT_SetBaudRate(ftHandle[i], 9600)) != FT_OK) {
        printf("Error FT_SetBaudRate(%d), cBufLD[i] = %s\n", (int)ftStatus, cBufLD[i]);
        break;
    }

    printf("Calling FT_Write with this write-buffer:\n");
    dumpBuffer(cBufWrite, BUF_SIZE);

    /* Write */
    ftStatus = FT_Write(ftHandle[i], cBufWrite, BUF_SIZE, &dwBytesWritten);
    if (ftStatus != FT_OK) {
        printf("Error FT_Write(%d)\n", (int)ftStatus);
        break;
    }
    if (dwBytesWritten != (DWORD)BUF_SIZE) {
        printf("FT_Write only wrote %d (of %d) bytes\n",
               (int)dwBytesWritten,
               BUF_SIZE);
        break;
    }
    sleep(1);

    /* Read */
    dwRxSize = 0;
    while ((dwRxSize < BUF_SIZE) && (ftStatus == FT_OK)) {
        ftStatus = FT_GetQueueStatus(ftHandle[i], &dwRxSize);
    }
    if(ftStatus == FT_OK) {
        pcBufRead = realloc(pcBufRead, dwRxSize);
        memset(pcBufRead, 0xFF, dwRxSize);
        printf("Calling FT_Read with this read-buffer:\n");
        dumpBuffer(pcBufRead, dwRxSize);
        ftStatus = FT_Read(ftHandle[i], pcBufRead, dwRxSize, &dwBytesRead);
        if (ftStatus != FT_OK) {
            printf("Error FT_Read(%d)\n", (int)ftStatus);
            break;
        }
        if (dwBytesRead != dwRxSize) {
            printf("FT_Read only read %d (of %d) bytes\n",
                   (int)dwBytesRead,
                   (int)dwRxSize);
            break;
        }
        printf("FT_Read read %d bytes.  Read-buffer is now:\n",
               (int)dwBytesRead);
        dumpBuffer(pcBufRead, (int)dwBytesRead);
        if (0 != memcmp(cBufWrite, pcBufRead, BUF_SIZE)) {
            printf("Error: read-buffer does not match write-buffer.\n");
            break;
        }
        printf("%s test passed.\n", cBufLD[i]);
    }
    else {
        printf("Error FT_GetQueueStatus(%d)\n", (int)ftStatus);
    }

}

  iDevicesOpen = i;
  /* Cleanup */
  for(i = 0; i < iDevicesOpen; i++) {
      FT_Close(ftHandle[i]);
      printf("Closed device %s\n", cBufLD[i]);
  }

  if(pcBufRead)
    free(pcBufRead);
  return 0;
}
4

0 回答 0