[英]undefined reference to `ftdi_init'
I have used libftdi in the past and compiled using the command: 我过去使用过libftdi,并使用以下命令进行编译:
gcc -lftdi -o i2csend i2csend.c gcc -lftdi -o i2csend i2csend.c
Everything went fine. 一切都很好。 Today, on Ubuntu 12.10 I get many errors such as
undefined reference to
ftdi_init'` 今天,在Ubuntu 12.10上,我遇到许多错误,例如
undefined reference to
ftdi_init的undefined reference to
I understand that libftdi was renamed to libftdi1 so I tried the same command with -lftdi1
and got error: 我知道libftdi被重命名为libftdi1,所以我用
-lftdi1
尝试了相同的命令并出现错误:
/usr/bin/ld: cannot find -lftdi1 collect2: error: ld returned 1 exit status / usr / bin / ld:找不到-lftdi1 collect2:错误:ld返回1退出状态
Can anyone explain why? 谁能解释为什么?
You should typically not directly specify external package's library names. 通常,您不应该直接指定外部软件包的库名。
It's better to use the packaging system's help program, ie pkg-config
, like so: 最好使用打包系统的帮助程序,即
pkg-config
,如下所示:
$ gcc -o i2csend i2csend.c $(pkg-config --cflags --libs libftdi1)
Note that this assumes that the package name is libftdi1
in pkg-config
's database; 注意,这里假设软件包名称在
pkg-config
的数据库中为libftdi1
; I'm not sure how to verify this portably. 我不确定如何便携地进行验证。 You can run
pkg-config --list-all | grep ftdi
您可以运行
pkg-config --list-all | grep ftdi
pkg-config --list-all | grep ftdi
to find out. pkg-config --list-all | grep ftdi
找出来。
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. 通常,将库部分(
-l
选项)保留在命令行的末尾是一个好主意,如上所述。 It's somewhat cleaner to factor out the CFLAGS
part, but that requires repeating the command: 剔除
CFLAGS
部分CFLAGS
干净,但这需要重复以下命令:
$ 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. 在这里,我使用双倍空格分隔命令行的逻辑部分,以提高清晰度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.