对 `ftdi_init' 的未定义引用 [英] undefined reference to `ftdi_init'

查看:40
本文介绍了对 `ftdi_init' 的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我过去使用过 libftdi 并使用以下命令编译:

I have used libftdi in the past and compiled using the command:

gcc -lftdi -o i2csend i2csend.c

gcc -lftdi -o i2csend i2csend.c

一切顺利.今天,在 Ubuntu 12.10 上,我收到许多错误,例如 undefined reference toftdi_init'`

Everything went fine. Today, on Ubuntu 12.10 I get many errors such as undefined reference toftdi_init'`

我知道 libftdi 被重命名为 libftdi1,所以我用 -lftdi1 尝试了相同的命令并得到错误:

I understand that libftdi was renamed to libftdi1 so I tried the same command with -lftdi1 and got error:

/usr/bin/ld: 找不到 -lftdi1collect2:错误:ld 返回 1 个退出状态

/usr/bin/ld: cannot find -lftdi1 collect2: error: ld returned 1 exit status

谁能解释一下为什么?

推荐答案

您通常不应直接指定外部包的库名称.

You should typically not directly specify external package's library names.

最好使用打包系统的帮助程序,即pkg-config,像这样:

It's better to use the packaging system's help program, i.e. pkg-config, like so:

$ gcc -o i2csend i2csend.c $(pkg-config --cflags --libs libftdi1)

注意这里假设包名是 pkg-config 的数据库中的 libftdi1 ;我不确定如何以可移植的方式验证这一点.您可以运行 pkg-config --list-all |grep ftdi 找出来.

Note that this assumes that the package name is libftdi1 in pkg-config's database; I'm not sure how to verify this portably. You can run pkg-config --list-all | grep ftdi to find out.

将库部分(-l 选项)保留在命令行的末尾通常是一个好主意,上面是这样做的.将 CFLAGS 部分分解出来会更简洁一些,但这需要重复命令:

It's generally a good idea to keep the libraries part (-l option) at the end of the command line, which the above is doing. It's somewhat cleaner to factor out the CFLAGS part, but that requires repeating the command:

$ gcc $(pkg-config --cflags libftdi1)  -o i2csend  i2csend.c  $(pkg-config --libs libftdi1)

在这里,我使用双空格分隔命令行的逻辑部分,以提高清晰度.

Here, I've used double spaces to separate the logical parts of the command line for improved clarity.

这篇关于对 `ftdi_init' 的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆