gpt4 book ai didi

ubuntu - 在 Ubuntu 上链接 libusb 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 16:51:49 27 4
gpt4 key购买 nike

我们正在尝试在需要 libusb 的 Ubuntu 机器上编译一些代码,但当它尝试链接到它时,我们不断收到“ undefined reference ”错误。

有问题的代码是这样的: https://gitorious.org/minibox-dcdcusb/minibox-dcdcusb

它需要 libusb,所以我安装了它:

apt-get install libusb libusb-dev

然后我运行 make 并得到以下错误:

➜  minibox-dcdcusb git:(master) ✗ make                    
cc -Wall main.c -o dcdc-usb `pkg-config --libs libusb` -lm -L. -ldcdc-usb
./libdcdc-usb.so: undefined reference to `usb_get_driver_np'
./libdcdc-usb.so: undefined reference to `usb_interrupt_read'
./libdcdc-usb.so: undefined reference to `usb_find_busses'
./libdcdc-usb.so: undefined reference to `usb_find_devices'
./libdcdc-usb.so: undefined reference to `usb_set_configuration'
./libdcdc-usb.so: undefined reference to `usb_interrupt_write'
./libdcdc-usb.so: undefined reference to `usb_control_msg'
./libdcdc-usb.so: undefined reference to `usb_set_altinterface'
./libdcdc-usb.so: undefined reference to `usb_init'
./libdcdc-usb.so: undefined reference to `usb_set_debug'
./libdcdc-usb.so: undefined reference to `usb_open'
./libdcdc-usb.so: undefined reference to `usb_claim_interface'
./libdcdc-usb.so: undefined reference to `usb_detach_kernel_driver_np'
./libdcdc-usb.so: undefined reference to `floor'
./libdcdc-usb.so: undefined reference to `usb_get_busses'
collect2: error: ld returned 1 exit status
make: *** [dcdc-usb] Error 1

我已验证 pkg-config 正在报告正确的配置参数:

➜  minibox-dcdcusb git:(master) ✗ pkg-config --libs libusb
-lusb

而且我已经确保二进制文件位于它们应该位于的位置:

➜  minibox-dcdcusb git:(master) ✗ ls -l /usr/lib/x86_64-linux-gnu/libusb*
lrwxrwxrwx 1 root root 37 des 3 13:58 /usr/lib/x86_64-linux-gnu/libusb-0.1.so.4 -> /lib/x86_64-linux-gnu/libusb-0.1.so.4
-rw-r--r-- 1 root root 42998 des 3 13:58 /usr/lib/x86_64-linux-gnu/libusb.a
lrwxrwxrwx 1 root root 41 des 3 13:58 /usr/lib/x86_64-linux-gnu/libusb.so -> /lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4

而且我什至确保链接器似乎提示的引用实际上在 libusb 二进制文件中:

(剧透:链接器提示的所有符号似乎都在那里)

最后,我使用 -Wl,--verbose 运行了编译命令,以准确查看链接器正在拾取的二进制文件,它似乎实际上是在拾取正确的二进制文件,但它无法链接他们。这是它的输出:

我完全不知道这里可能是什么问题?为什么链接器无法链接到 libusb?

最佳答案

Why isn't the linker able to link against libusb?

它可以,但是当链接器看到该库时,它没有对 libusb 中符号的任何 undefined reference ,因此它继续前进并忽略它。稍后链接器看到 libdcdc-usb,它对 libusb 中的符号有 undefined reference ,但为时已晚,链接器已经关闭 libusb 并停止查看它。

正如评论所说,链接器参数的顺序很重要,但评论建议将它们移到更早的位置,这是错误的做法。

In fact I read somewhere that the linker information should come after the source argument that requires that library.

这不仅仅是“源文件之后的链接器参数”,您需要对库进行排序,以便提供符号定义的库出现在需要这些定义的对象之后。

libdcdc-usb 依赖于 libusb 所以 libusb 必须稍后,所以移动 pkg-config调用结束。

关于ubuntu - 在 Ubuntu 上链接 libusb 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23549833/

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