在arm linux Qt下编译配置libusb1.0

一、配置环境

1.安装arm-linux-gcc编译器

2.编译qt-everywhere并安装

3.安装qt creator

具体参考:http://www.cnblogs.com/oceanking/archive/2012/09/04/2671150.html

二、编译安装libusb-1.0

到libusb网站下载libusb

www.libusb.org

1.解压后cd进入该文件夹,顺序执行如下命令:(需要确保已经将arm-linux-gcc所在路径加入PATH中)

./configure CC=arm-linux-gcc CXX=arm-linux-g++ --build=i686-linux --host=arm-linux
make
sudo make install

默认将lib安装到/usr/local/lib,头文件安装在/usr/local/include,如果需要修改安装路径,则在./configure 增加参数 --prefix=/path/to/install

注意:如果在sudo make install 时提示:

arm-linux-ranlib: command not found

则说明PATH配置不完全正确,导致root用户与当前用户的PATH不同。解决方法是先使用su命令取得root权限然后执行make install。首次使用su会提示:

su: Authentication failure

使用命令

$ sudo passwd root
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

 即可取得root权限,以后也可以直接使用su命令了。

2.配置Qt工程文件(.pro),增加如下内容

unix:INCLUDEPATH += /usr/local/include
unix:LIBS += -L/usr/local/lib -lusb-1.0

第一行表示在项目中引用头文件的默认路径。

第二行表示指定Qt编译时去/usr/local/lib路径找libusb-1.0的链接库。

qt源文件中需要引用头文件

#include <libusb-1.0/libusb.h>

代码中调用libusb的方法可参考源码中的例子。

原文地址:https://www.cnblogs.com/oceanking/p/2671119.html