在 Ubuntu 上针对 libusb-dev 进行编译
我正在尝试编译 libusb 包提供的示例 libusb.c (如果您 dl 源代码)。
至少可以说它不起作用。
#include <stdio.h>
#include <sys/types.h>
#include <libusb/libusb.h>
这导致它失败,没有 libusb/libusb.h
它是 usb.h
,所以我改变了它。它以新的和创新的方式失败了。
我已经准确地复制了该文件,并将其命名为 example.c
我正在使用这些命令和变体:
gcc -o example example.c -lusb -L /usr/lib/libusb.a
gcc -o example example.c -lusb -L /usr/lib/libusb.so
编译时遇到的错误是:
example.c:25: error: expected ‘)’ before ‘*’ token
example.c: In function ‘main’:
example.c:46: error: ‘libusb_device’ undeclared (first use in this function)
example.c:46: error: (Each undeclared identifier is reported only once
example.c:46: error: for each function it appears in.)
example.c:46: error: ‘devs’ undeclared (first use in this function)
Line 25: static void print_devs(libusb_device **devs)
Line 46: libusb_device **devs;
起初我遵循了教程,但未能编译,或多或少同样的方式,所以我决定尝试提供的示例,但失败了。
有人可以帮我吗?解释一下我做错了什么,因为我迷失了这一点。
I am trying to compile the example libusb.c provided by libusb package (if you dl the source code.)
It doesn't work to say the least.
#include <stdio.h>
#include <sys/types.h>
#include <libusb/libusb.h>
That causes it to fail, there is no libusb/libusb.h
it's usb.h
, so I change that. And it fails in new and innovative ways.
I've copied the file over, exactly, and named it example.c
I am using these commands and variations:
gcc -o example example.c -lusb -L /usr/lib/libusb.a
gcc -o example example.c -lusb -L /usr/lib/libusb.so
The errors I get when compiling are:
example.c:25: error: expected ‘)’ before ‘*’ token
example.c: In function ‘main’:
example.c:46: error: ‘libusb_device’ undeclared (first use in this function)
example.c:46: error: (Each undeclared identifier is reported only once
example.c:46: error: for each function it appears in.)
example.c:46: error: ‘devs’ undeclared (first use in this function)
Line 25: static void print_devs(libusb_device **devs)
Line 46: libusb_device **devs;
At first I followed a tutorial, and that failed to compile, in more or less the same ways, so I decided to just try the provided example, and that failed.
Can anyone help me out? Explain what I am doing wrong, cause I am lost on this one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我在 Debian 上必须做的事情。至少在 Ubuntu 中应该是类似的。
安装
libusb-1.0-0-dev
而不是:
do:
编译为:
This is what I had to do on Debian. It should be at least similar in Ubuntu.
Install
libusb-1.0-0-dev
Instead of:
do:
Compile with:
只是解释为什么您尝试用
usb.h
替换libusb/libusb.h
失败:usb.h
是来自的标头linux-headers
,不是来自libusb-dev
。您需要#include
来代替。Just en explanation why your attempt to replace
libusb/libusb.h
withusb.h
fails:usb.h
is a header fromlinux-headers
, not fromlibusb-dev
. You need#include <libusb.h>
instead.