Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

No matter what I run I get,

./main.c:1:10: fatal error: libusb.h: No such file or directory
 #include "libusb.h"
          ^~~~~~~~~~
compilation terminated.

Things tried

gcc ./main.c -l/usr/include/libusb-1.0/
gcc ./main.c -l/usr/include/
gcc ./main.c -L/usr/include/libusb-1.0/
gcc ./main.c -L/usr/include/

If I try

#include "libusb-1.0/libusb.h"

instead of

#include "libusb.h"

It compiles, but I get

/tmp/ccLn3qR2.o: In function `main':
main.c:(.text+0x17): undefined reference to `libusb_init'
main.c:(.text+0x2b): undefined reference to `libusb_open_device_with_vid_pid'
main.c:(.text+0x46): undefined reference to `libusb_release_interface'
main.c:(.text+0x55): undefined reference to `libusb_close'
collect2: error: ld returned 1 exit status

I get the same thing (the above errors) with

gcc ./main.c -I/usr/include/libusb-1.0

I see a lot of people getting similar errors, but I can find the solution. These seem to be documented here.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
188 views
Welcome To Ask or Share your Answers For Others

1 Answer

What ended up working, was specifying the path in the .h file,

#include "libusb-1.0/libusb.h"

Which includes /usr/include/libusb-1.0/libusb.h. And, then compiling with,

gcc ./main.c -lusb-1.0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...