Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

ubuntu - Compiling with libusb?

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

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

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...