在 Ubuntu 上针对 libusb-dev 进行编译

发布于 2024-12-09 14:06:06 字数 1042 浏览 1 评论 0原文

我正在尝试编译 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许一世地老天荒 2024-12-16 14:06:06

这就是我在 Debian 上必须做的事情。至少在 Ubuntu 中应该是类似的。

安装 libusb-1.0-0-dev

而不是:

#include <libusb/libusb.h>

do:

#include <libusb.h>

编译为:

gcc example.c `pkg-config --libs --cflags libusb-1.0`

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:

#include <libusb/libusb.h>

do:

#include <libusb.h>

Compile with:

gcc example.c `pkg-config --libs --cflags libusb-1.0`
梦巷 2024-12-16 14:06:06

只是解释为什么您尝试用 usb.h 替换 libusb/libusb.h 失败:usb.h 是来自 的标头linux-headers,不是来自 libusb-dev。您需要 #include 来代替。

Just en explanation why your attempt to replace libusb/libusb.h with usb.h fails: usb.h is a header from linux-headers, not from libusb-dev. You need #include <libusb.h> instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文