gpt4 book ai didi

c - 使用 cygwin 通过 FTDI 使用 ftd2xx.lib 编译 c 应用程序

转载 作者:行者123 更新时间:2023-11-30 15:01:04 27 4
gpt4 key购买 nike

我试图在 cygwin 中使用 gcc 使用 FTDI 的 ftd2xx lib 编译示例 64 位 c 程序,但没有成功。我总是遇到链接器错误。

我的项目包含这些文件:

  • main.c 我的示例应用程序
  • ftd2xx.h 库的头文件
  • ftd2xx.lib 导入库
  • ftd2xx64.dll动态库64位
  • wintypes.h ftd2xx.h 使用的包装器来包含 windows.h

这是我的主要功能:

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

这是我的链接器cmd

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$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)

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

最佳答案

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

关于c - 使用 cygwin 通过 FTDI 使用 ftd2xx.lib 编译 c 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41721944/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com