gpt4 book ai didi

c - 未定义的引用错误

转载 作者:行者123 更新时间:2023-11-30 19:38:11 25 4
gpt4 key购买 nike

编辑:当然,完全重复,并不是 stackoverflow 提出问题并获得具体答案的全部意义,您链接到我的“答案”是:A. 对于 C++,所以部分难以理解B. 读起来就像一篇 wiki 文章,内容庞大,一点也不具体,也没有一点帮助。

我已经从下载的代码库(libftdi)中的示例文件夹中复制了一段示例代码,到我想要编写项目的位置,当我运行它时,它有很多 undefined reference ,但是它运行在原来的位置很好。

主文件:

#include <stdio.h>
#include <stdlib.h>
#include <ftdi.h>

int main(void)
{
int ret, i;
struct ftdi_context *ftdi;
struct ftdi_device_list *devlist, *curdev;
char manufacturer[128], description[128];
int retval = EXIT_SUCCESS;

if ((ftdi = ftdi_new()) == 0)
{
fprintf(stderr, "ftdi_new failed\n");
return EXIT_FAILURE;
}

if ((ret = ftdi_usb_find_all(ftdi, &devlist, 0, 0)) < 0)
{
fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(ftdi));
retval = EXIT_FAILURE;
goto do_deinit;
}

printf("Number of FTDI devices found: %d\n", ret);

i = 0;
for (curdev = devlist; curdev != NULL; i++)
{
printf("Checking device: %d\n", i);
if ((ret = ftdi_usb_get_strings(ftdi, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0)
{
fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", ret, ftdi_get_error_string(ftdi));
retval = EXIT_FAILURE;
goto done;
}
printf("Manufacturer: %s, Description: %s\n\n", manufacturer, description);
curdev = curdev->next;
}
done:
ftdi_list_free(&devlist);
do_deinit:
ftdi_free(ftdi);

return retval;
}

错误:

ollieb@ursus ~/Documents/BitBang $ make
make bitbang
make[1]: Entering directory '/home/ollieb/Documents/BitBang'
cc -Wall -g -I/usr/include/libftdi1/ bitbang.c -o bitbang
/tmp/cc20kltT.o: In function `main':
/home/ollieb/Documents/BitBang/bitbang.c:13: undefined reference to `ftdi_new'
/home/ollieb/Documents/BitBang/bitbang.c:19: undefined reference to `ftdi_usb_find_all'
/home/ollieb/Documents/BitBang/bitbang.c:21: undefined reference to `ftdi_get_error_string'
/home/ollieb/Documents/BitBang/bitbang.c:32: undefined reference to `ftdi_usb_get_strings'
/home/ollieb/Documents/BitBang/bitbang.c:34: undefined reference to `ftdi_get_error_string'
/home/ollieb/Documents/BitBang/bitbang.c:42: undefined reference to `ftdi_list_free'
/home/ollieb/Documents/BitBang/bitbang.c:44: undefined reference to `ftdi_free'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'bitbang' failed
make[1]: *** [bitbang] Error 1
make[1]: Leaving directory '/home/ollieb/Documents/BitBang'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

制作文件:

CFLAGS=-Wall -g -I/usr/include/libftdi1/

all:
make bitbang

clean:
rm bitbang

最佳答案

您必须链接到 ftdi 库 (-Llibdirectory -llib)

关于c - 未定义的引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38588344/

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