![编译 LibUSB 0.1 程序失败,出现“未定义引用”错误](https://linux22.com/image/1169293/%E7%BC%96%E8%AF%91%20LibUSB%200.1%20%E7%A8%8B%E5%BA%8F%E5%A4%B1%E8%B4%A5%EF%BC%8C%E5%87%BA%E7%8E%B0%E2%80%9C%E6%9C%AA%E5%AE%9A%E4%B9%89%E5%BC%95%E7%94%A8%E2%80%9D%E9%94%99%E8%AF%AF.png)
我有一个使用 的小型 C 程序libusb 0.1
。
我已经安装了libusb-dev
(基本上意味着 libusb 0.1:https://packages.ubuntu.com/de/xenial/libusb-dev) 并包含标题<usb.h>
。
但使用 编译gcc -Wall -lusb -o te923con te923con.c te923usb.c te923com.c
总是失败。有很多未定义的引用,包括usb_find_busses
、usb_init
和usb_open
。
$ gcc -Wall -lusb -o te923con te923con.c te923usb.c te923com.c
/tmp/cc1TRIze.o: In function `find_te923':
te923usb.c:(.text+0x9): undefined reference to `usb_find_busses'
te923usb.c:(.text+0xe): undefined reference to `usb_find_devices'
te923usb.c:(.text+0x13): undefined reference to `usb_get_busses'
/tmp/cc1TRIze.o: In function `te923_handle':
te923usb.c:(.text+0xf9): undefined reference to `usb_init'
te923usb.c:(.text+0x144): undefined reference to `usb_open'
te923usb.c:(.text+0x191): undefined reference to `usb_get_driver_np'
te923usb.c:(.text+0x1ab): undefined reference to `usb_detach_kernel_driver_np'
te923usb.c:(.text+0x1bc): undefined reference to `usb_set_configuration'
te923usb.c:(.text+0x1fe): undefined reference to `usb_claim_interface'
te923usb.c:(.text+0x23d): undefined reference to `usb_set_altinterface'
/tmp/cc1TRIze.o: In function `te923_close':
te923usb.c:(.text+0x2b3): undefined reference to `usb_release_interface'
te923usb.c:(.text+0x2bf): undefined reference to `usb_close'
/tmp/ccxL1A67.o: In function `read_from_te923':
te923com.c:(.text+0x19e): undefined reference to `usb_control_msg'
te923com.c:(.text+0x28b): undefined reference to `usb_interrupt_read'
collect2: error: ld returned 1 exit status
Makefile:5: recipe for target 'te923con' failed
make: *** [te923con] Error 1
我不明白这些错误的原因。有人知道吗?
答案1
我遇到了类似的问题。我解决了
代替
gcc -lusb -o outfile input.c
我用了
gcc -o outfile input.c -lusb
并且有效