在Ubuntu上交叉编译libusb,libusb

***********************************************************************
Ubuntu上交叉编译libusb,libusb-compat,usbutils和usb_modeswitch  ***
***********************************************************************

编译环境:Ubuntu 9.04,arm-linux-gcc-3.4.4.
编译对象:libusb-1.0.2,libusb-compat-0.1.3,usbutils-0.11和usb_modeswitch-1.0.5
工具说明:
usb_modeswitch
实现无线上网卡从USB Storage模式切换到Modem模式,详见:
libusb、libusb-compat
usb_modeswitch需要libusb的支持。
libusb分为1.0版和0.1版两种版本,1.0并不向下兼容0.1,需要libusb-compat的支持;因此,你可以同时装上1.0和0.1,但不可同时装0.1版和libusb-compat。详见:
usbutils
Linux下查看usb设备信息的工具

 

/*

 *下面主要记录libusb和libusb-compat部分,毕竟过了有一段时间,有些当时遇到的问题现在记不清了

 */
交叉编译前,首先进行配置。在终端上敲入配置命令:./configure --host=arm-linux  --prefix=<Your Install DIR>
配置结束后,再输入make install,按回车,出现一堆信息。其中,最后一部分信息为:

***********************清单1*****************************
...
Libraries have been installed in:
   <Your Install DIR>

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.
...
********************************************************


因为接下来也要交叉编译其他工具,它们都需要libusb库的支持,所以要将libusb生成的库放到工具链对应的文件夹下(/opt/crosstool/arm-linux/gcc-3.4.4-glibc-2.3.5/arm-linux/arm-linux下的lib以及include)。

如果这时只将头文件和库复制到相应的目录,然后继续编译libusb-compat时会出现一个问题。
就是当你输入配置命令./configure  --host=arm-linux  --prefix=<Your Install DIR>
后会出现提示,表示没找到LIBUSB包。(这个问题其实在清单1上有提示)

*************************清单2**************************
...
checking for LIBUSB_1_0... configure: error: Package requirements (libusb-1.0 >= 0.9.1) were not met:

No package 'libusb-1.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBUSB_1_0_CFLAGS
and LIBUSB_1_0_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
...
*********************************************************


出现这个是因为没有把libusb生成的pkgconfig下的.pc文件复制过去(还要修改里面的prefix路径参数),详见:
如果复制之后仍未解决,试着添加PKG_CONFIG_PATH.


成功后,终端上对应的打印信息是
**************************清单3**************************
...
checking for LIBUSB_1_0... yes
configure: creating ./config.status
config.status: creating libusb.pc
config.status: creating libusb-config
config.status: creating Makefile
config.status: creating libusb/Makefile
config.status: creating examples/Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing default commands
...
*********************************************************

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwxsjy.html