编译 LibUSB 0.1 程序失败,出现“未定义引用”错误

编译 LibUSB 0.1 程序失败,出现“未定义引用”错误

我有一个使用 的小型 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_bussesusb_initusb_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

并且有效

相关内容