简体   繁体   English

如何在 Ubuntu 中安装 libusb

[英]How to install libusb in Ubuntu

I have a C program that have #include part in the header.我有一个 C 程序,在头中有 #include 部分。

I have download libusb-1.0.0 to my computer.我已经将 libusb-1.0.0 下载到我的电脑上。 If I simply copy libusb-1.0.0 folder to the folder where my C program is, it will not work.如果我只是简单地将 libusb-1.0.0 文件夹复制到我的 C 程序所在的文件夹中,它将无法工作。 Therefore, I think I have to somehow install libuse-1.-.- to the folder where my C program is.因此,我想我必须以某种方式将 libuse-1.-.- 安装到我的 C 程序所在的文件夹中。 However, I do not how to install it.但是,我不知道如何安装它。

Could anybody please help me.任何人都可以请帮助我。 Thanks!谢谢!

Usually to use the library you need to install the dev version.通常要使用您需要安装开发版本的库。

Try试试

sudo apt-get install libusb-1.0-0-dev

这应该有效:

# apt-get install libusb-1.0-0-dev

First ,首先

sudo apt-get install libusb-1.0-0-dev

updatedb && locate libusb.h.

Second , replace <libusb.h> with <libusb-1.0/libusb.h> .其次,将<libusb.h>替换为<libusb-1.0/libusb.h>

update:更新:

don't need to change any file.just add this to your Makefile.不需要更改任何文件。只需将其添加到您的 Makefile 中即可。

`pkg-config libusb-1.0 --libs --cflags`

its result is that -I/usr/include/libusb-1.0 -lusb-1.0它的结果是-I/usr/include/libusb-1.0 -lusb-1.0

Here is what worked for me.这对我有用。

Install the userspace USB programming library development files安装用户空间USB编程库开发文件

sudo apt-get install libusb-1.0-0-dev
sudo updatedb && locate libusb.h

The path should appear as (or similar)路径应显示为(或类似)

/usr/include/libusb-1.0/libusb.h

Include the header to your C code在 C 代码中包含标头

#include <libusb-1.0/libusb.h>

Compile your C file编译你的 C 文件

gcc -o example example.c -lusb-1.0

My two cents: libusbx is pretty active lately and works like a charm on Debian GNU/Linux (should be the same for Ubuntu). 我的两分钱: libusbx最近很活跃,就像Debian GNU / Linux上的魅力一样(对于Ubuntu应该是一样的)。 Then 然后

$ ./configure && make && make install && sudo ldconfig

will drop libusbx to /usr/local . 将libusbx放到/usr/local

"I need to install it to the folder of my C program." “我需要将它安装到我的 C 程序的文件夹中。” Why?为什么?

Include usb.h:包括usb.h:

#include <usb.h>

and remember to add -lusb to gcc:并记得将 -lusb 添加到 gcc:

gcc -o example example.c -lusb

This work fine for me.这对我来说很好。

you can creat symlink to your libusb after locate it in your system :在您的系统中找到它后,您可以创建指向您的 libusb 的符号链接:

sudo ln -s /lib/x86_64-linux-gnu/libusb-1.0.so.0 /usr/lib/libusbx-1.0.so.0.1.0 

sudo ln -s /lib/x86_64-linux-gnu/libusb-1.0.so.0 /usr/lib/libusbx-1.0.so

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM