linux下libusb的安装与测试
0.libusb的介绍:参考[1]
1.环境:vmware_fedora_10(linux-2.6.x)
2.获取源代码:http://sourceforge.net/projects/libusb/ (最好选择libusb-1.0.9版本,下载次数最多,自是有它的道理)
3.解压源码tar xjvf libusb-1.0.9.tar.bz2 按照INSTALL文件给出的提示进行安装:主要分为./configure ->make -> make install
4.安装过程如下:
configure略去......(看不懂......)
make
make all-recursive
make[1]: Entering directory `/share/libusb-1.0.9'
Making all in libusb
make[2]: Entering directory `/share/libusb-1.0.9/libusb'
CC libusb_1_0_la-core.lo
CC libusb_1_0_la-descriptor.lo
CC libusb_1_0_la-io.lo
CC libusb_1_0_la-sync.lo
CC libusb_1_0_la-linux_usbfs.lo
CC libusb_1_0_la-threads_posix.lo
CCLD libusb-1.0.la
make[2]: Leaving directory `/share/libusb-1.0.9/libusb'
Making all in doc
make[2]: Entering directory `/share/libusb-1.0.9/doc'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/share/libusb-1.0.9/doc'
make[2]: Entering directory `/share/libusb-1.0.9'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/share/libusb-1.0.9'
make[1]: Leaving directory `/share/libusb-1.0.9'
make install
Making install in libusb
make[1]: Entering directory `/share/libusb-1.0.9/libusb'
make[2]: Entering directory `/share/libusb-1.0.9/libusb'
test -z "/usr/local/lib" || /bin/mkdir -p "/usr/local/lib"
/bin/sh ../libtool --mode=install /usr/bin/install -c libusb-1.0.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libusb-1.0.so.0.1.0 /usr/local/lib/libusb-1.0.so.0.1.0
libtool: install: (cd /usr/local/lib && { ln -s -f libusb-1.0.so.0.1.0 libusb-1.0.so.0 || { rm -f libusb-1.0.so.0 && ln -s libusb-1.0.so.0.1.0 libusb-1.0.so.0; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libusb-1.0.so.0.1.0 libusb-1.0.so || { rm -f libusb-1.0.so && ln -s libusb-1.0.so.0.1.0 libusb-1.0.so; }; })
libtool: install: /usr/bin/install -c .libs/libusb-1.0.lai /usr/local/lib/libusb-1.0.la
libtool: install: /usr/bin/install -c .libs/libusb-1.0.a /usr/local/lib/libusb-1.0.a
libtool: install: chmod 644 /usr/local/lib/libusb-1.0.a
libtool: install: ranlib /usr/local/lib/libusb-1.0.a
libtool: finish: PATH="/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/opt/EmbedSky/4.3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib/* 这里提示已经将库加入到/usr/local/lib目录,所以我们基于libusb编程的时候,需要包含这个库 */
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/local/include/libusb-1.0" || /bin/mkdir -p "/usr/local/include/libusb-1.0"
/usr/bin/install -c -m 644 libusb.h '/usr/local/include/libusb-1.0'
make[2]: Leaving directory `/share/libusb-1.0.9/libusb'
make[1]: Leaving directory `/share/libusb-1.0.9/libusb'
Making install in doc
make[1]: Entering directory `/share/libusb-1.0.9/doc'
make[2]: Entering directory `/share/libusb-1.0.9/doc'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/share/libusb-1.0.9/doc'
make[1]: Leaving directory `/share/libusb-1.0.9/doc'
make[1]: Entering directory `/share/libusb-1.0.9'
make[2]: Entering directory `/share/libusb-1.0.9'
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/lib/pkgconfig" || /bin/mkdir -p "/usr/local/lib/pkgconfig"
/usr/bin/install -c -m 644 libusb-1.0.pc '/usr/local/lib/pkgconfig'
make[2]: Leaving directory `/share/libusb-1.0.9'
make[1]: Leaving directory `/share/libusb-1.0.9'
5.源码目录下有example目录,是libusb提供的测试程序listdev.c (列出usb设备)
- #include <stdio.h>
- #include <sys/types.h>
- #include <libusb.h>
- static void print_devs(libusb_device **devs)
- {
- libusb_device *dev;
- int i = 0;
- while ((dev = devs[i++]) != NULL) {
- struct libusb_device_descriptor desc;
- int r = libusb_get_device_descriptor(dev, &desc);
- if (r < 0) {
- fprintf(stderr, "failed to get device descriptor");
- return;
- }
- printf("%04x:%04x (bus %d, device %d)\n",
- desc.idVendor, desc.idProduct,
- libusb_get_bus_number(dev), libusb_get_device_address(dev));
- }
- }
- int main(void)
- {
- libusb_device **devs;
- int r;
- ssize_t cnt;
- r = libusb_init(NULL);
- if (r < 0)
- return r;
- cnt = libusb_get_device_list(NULL, &devs);
- if (cnt < 0)
- return (int) cnt;
- print_devs(devs);
- libusb_free_device_list(devs, 1);
- libusb_exit(NULL);
- return 0;
- }
#include <stdio.h>
#include <sys/types.h>
#include <libusb.h> static void print_devs(libusb_device **devs)
{
libusb_device *dev;
int i = 0; while ((dev = devs[i++]) != NULL) {
struct libusb_device_descriptor desc;
int r = libusb_get_device_descriptor(dev, &desc);
if (r < 0) {
fprintf(stderr, "failed to get device descriptor");
return;
} printf("%04x:%04x (bus %d, device %d)\n",
desc.idVendor, desc.idProduct,
libusb_get_bus_number(dev), libusb_get_device_address(dev));
}
} int main(void)
{
libusb_device **devs;
int r;
ssize_t cnt; r = libusb_init(NULL);
if (r < 0)
return r; cnt = libusb_get_device_list(NULL, &devs);
if (cnt < 0)
return (int) cnt; print_devs(devs);
libusb_free_device_list(devs, 1); libusb_exit(NULL);
return 0;
}
编译的时候我们可以用自带的makefile生成可执行文件,也可以用如下操作进行:(参考[2])
[root@zx examples]# gcc -I/usr/local/include/libusb-1.0 listdevs.c -L/usr/local/lib -lusb-1.0
-I包含头文件 ;-L链接库
6.listdev的运行结果如下:
[root@zx examples]# gcc -I/usr/local/include/libusb-1.0 listdevs.c -L/usr/local/lib -lusb-1.0
[root@zx examples]# ./a.out
1d6b:0002 (bus 1, device 1)
1d6b:0001 (bus 2, device 1)
0e0f:0003 (bus 2, device 2)
0e0f:0002 (bus 2, device 3)
0cf3:1006 (bus 1, device 3)
[root@zx examples]# lsusb 7.若想打开调试开关,看出libusb内部的运行情况
在libusb/libusbi.h中有如下代码
- #ifdef ENABLE_DEBUG_LOGGING
- #define usbi_dbg(...) _usbi_log(NULL, LOG_LEVEL_DEBUG, __VA_ARGS__)
- #else
- #define usbi_dbg(...) do {} while(0)
- #endif
#ifdef ENABLE_DEBUG_LOGGING
#define usbi_dbg(...) _usbi_log(NULL, LOG_LEVEL_DEBUG, __VA_ARGS__)
#else
#define usbi_dbg(...) do {} while(0)
#endif
所以说在makefile加上-DENABLE_DEBUG_LOGGING=1这个编译选项即可.
在libusb的目录下找到makefile(configure之后才会生成),找到CFLAGS = -g -O2,替换为CFLAGS = -g -O2 -DENABLE_DEBUG_LOGGING=1
再次make和make install,切换到之前的listdev程序,可以看见已经打出libusb内部的调用顺序:
[root@zx examples]# ./listdevs
libusb: 0.000000 debug [libusb_init] libusb-1.0.9
libusb: 0.003326 debug [find_usbfs_path] found usbfs at /dev/bus/usb
libusb: 0.004064 debug [op_init] found usb devices in sysfs
libusb: 0.004939 debug [usbi_add_pollfd] add fd 3 events 1
libusb: 0.005519 debug [usbi_io_init] using timerfd for timeouts
libusb: 0.006147 debug [usbi_add_pollfd] add fd 5 events 1
libusb: 0.006710 debug [libusb_init] created default context
libusb: 0.007273 debug [libusb_get_device_list]
libusb: 0.011264 debug [sysfs_scan_device] scan usb1
libusb: 0.012133 debug [sysfs_scan_device] bus=1 dev=1
libusb: 0.012681 debug [enumerate_device] busnum 1 devaddr 1 session_id 257
libusb: 0.013244 debug [enumerate_device] allocating new device for 1/1 (session 257)
libusb: 0.013956 debug [sysfs_scan_device] scan usb2
libusb: 0.014740 debug [sysfs_scan_device] bus=2 dev=1
libusb: 0.015685 debug [enumerate_device] busnum 2 devaddr 1 session_id 513
libusb: 0.016251 debug [enumerate_device] allocating new device for 2/1 (session 513)
libusb: 0.016984 debug [sysfs_scan_device] scan 2-1
libusb: 0.017761 debug [sysfs_scan_device] bus=2 dev=2
libusb: 0.018467 debug [enumerate_device] busnum 2 devaddr 2 session_id 514
libusb: 0.018988 debug [enumerate_device] allocating new device for 2/2 (session 514)
libusb: 0.019789 debug [sysfs_scan_device] scan 2-2
libusb: 0.020473 debug [sysfs_scan_device] bus=2 dev=3
libusb: 0.021145 debug [enumerate_device] busnum 2 devaddr 3 session_id 515
libusb: 0.021742 debug [enumerate_device] allocating new device for 2/3 (session 515)
libusb: 0.022440 debug [sysfs_scan_device] scan 1-1
libusb: 0.023203 debug [sysfs_scan_device] bus=1 dev=3
libusb: 0.023986 debug [enumerate_device] busnum 1 devaddr 3 session_id 259
libusb: 0.024548 debug [enumerate_device] allocating new device for 1/3 (session 259)
libusb: 0.025266 debug [libusb_get_device_descriptor]
1d6b:0002 (bus 1, device 1)
libusb: 0.026017 debug [libusb_get_device_descriptor]
1d6b:0001 (bus 2, device 1)
libusb: 0.026479 debug [libusb_get_device_descriptor]
0e0f:0003 (bus 2, device 2)
libusb: 0.026516 debug [libusb_get_device_descriptor]
0e0f:0002 (bus 2, device 3)
libusb: 0.026576 debug [libusb_get_device_descriptor]
0cf3:1006 (bus 1, device 3)
libusb: 0.026616 debug [libusb_unref_device] destroy device 1.1
libusb: 0.026636 debug [libusb_unref_device] destroy device 2.1
libusb: 0.026652 debug [libusb_unref_device] destroy device 2.2
libusb: 0.026667 debug [libusb_unref_device] destroy device 2.3
libusb: 0.026682 debug [libusb_unref_device] destroy device 1.3
libusb: 0.026698 debug [libusb_exit]
libusb: 0.026731 debug [libusb_exit] destroying default context
libusb: 0.026747 debug [usbi_remove_pollfd] remove fd 3
libusb: 0.026778 debug [usbi_remove_pollfd] remove fd 5
http://baike.baidu.com/view/4598042.htm
[2].解决编译问题:http://libusb.6.n5.nabble.com/Compile-my-program-td2645564.html
linux下libusb的安装与测试的更多相关文章
- Windows下的Memcache安装 linux下的Memcache安装
linux下的Memcache安装: 1. 下载 memcache的linux版本,注意 memcached 用 libevent 来作事件驱动,所以要先安装有 libevent. 官方网址:http ...
- linux下subversion server安装手册
linux下subversion server安装手册 安装基于的Linux版本为:Red Hat Enterprise Linux Server release 6.3. 一 准备需要的安装包. ( ...
- Linux下Perl的安装(转)
原文地址:Linux下Perl的安装 今天在虚拟机测试shell脚本的时候,有些命令使用不了. 比如说 mysqlhotcopy ,它提示Perl的版本太低. 我用的 RedHat9 的Perl才5. ...
- 细说Linux下软件包的安装与管理
一 源码安装方式 由于linux操作系统开放源代码,因而在其上安装的软件大部分也都是开源软件,例如apache.tomcat.php等软件.开源软件基本都提供源码下载,源码安装的方式:源码安 ...
- coreseek实战(一):windows下coreseek的安装与测试
coreseek实战(一):windows下coreseek的安装与测试 网上关于 coreseek 在 windows 下安装与使用的教程有很多,官方也有详细的教程,这里我也只是按着官方提供的教程详 ...
- Linux下OpenSSL的安装与使用
Linux下OpenSSL的安装与使用 OpenSSL简介 OpenSSL是一个SSL协议的开源实现,采用C语言作为开发语言,具备了跨平台的能力,支持Unix/Linux.Windows.Mac OS ...
- Linux 下编译、安装、配置 QT
转自Linux 下编译.安装.配置 QT 注意:编译安装耗时费力,且很容易出错,要不断调整编译参数,不推荐使用,否则这将会是一个纠结痛苦的过程. 打算做嵌入式图像处理,计划方案嵌入式Linux+Ope ...
- Linux下tomcat的安装详解
Linux下tomcat的安装详解 来源: ChinaUnix博客 日期: 2007.01.21 22:59 (共有0条评论) 我要评论 一,安装前的准备:1,Linux版本:我的是企业版.(至于红帽 ...
- .Neter玩转Linux系列之六:Linux下MySQL的安装、配置、使用
一.Linux安装MySQL (1)下载安装包:https://dev.mysql.com/downloads/mysql/ (2)解压并安装 命令:tar zxvf 文件名 解压完成之后,重名一下文 ...
随机推荐
- css实现两个div并排等高(一个div高度随另一个高度变化而变化)
方法一.两个div都设置 display: table-cell; 方法二.父级div设置 display: -webkit-box;
- git大全转
git原理:https://git-scm.com/book/zh/v2 http://blog.xiayf.cn/2013/09/28/learning-git-internals-by-examp ...
- Windows向Linux上传文件夹
1.将文件夹压缩成.tar.gz文件: 安装7-Zip,选择要压缩的文件夹--右键--“7-Zip”--“添加到压缩包...”,压缩格式选择“tar”, 在此目下就生成了“文件夹名.tar”文件, ...
- 从零开始学MySQL(二)
鉴于上节篇幅以安装为主,因此对于调用mysql所需要使用的“命令”只是略微提及.随之而来就会带给读者诸多不解了,因为你会思考,这串长长的字符到底有什么特殊的含义呢?聪明的你可能早就抱着好奇心去“摆渡” ...
- RubyGems 库发现了后门版本的网站开发工具 bootstrap-sass
安全研究人员在官方的 RubyGems 库发现了后门版本的网站开发工具 bootstrap-sass.该工具的下载量高达 2800 万次,但这并不意味着下载的所有版本都存在后门,受影响的版本是 v3. ...
- LDO ,开关电源DC-DC的优缺点
一般LDO电源自身的功耗为(Vin-Vout)*Iout,因此这两者越大,功耗也越大,效率也就越低. LDO ,开关电源DC-DC的优缺点(2008-11-06 22:40:23)转载标签: 电源杂谈 ...
- SpringMVC 向页面传值-Map、Model和ModelMap
除了使用ModelAndView方式外.还可以使用Map.Model和ModelMap来向前台页面传值 使用后面3种方式,都是在方法参数中,指定一个该类型的参数.例如: Java代码 @Request ...
- 【Python系列】Python自动发邮件脚本
缘起 这段时间给朋友搞了个群发邮件的脚本,为了防止进入垃圾邮件,做了很多工作,刚搞完,垃圾邮件进入率50%,觉得还不错,如果要将垃圾邮件的进入率再调低,估计就要花钱买主机了,想想也就算了,先发一个月, ...
- Connection refused 排查过程
Connection refused 排查过程 connection refused 排查 起因 今天在连接 rabbitmq 时,报 Connection refused (如下图),借此机会记 ...
- 使用vux的x-input组件中show-clear=“true”清除icon点击失效的问题
问题场景: 在电脑浏览器点击清除icon正常 在手机浏览器,手机微信,微信开发者工具中点击清除icon失效 查看vux中的x-input组件中的源码发现,清除icon使用了v-show显示与隐藏,对应 ...