在Ubuntu上交叉编译libusb,libusbcompat,usbutils和usb_modeswitch [转]

***********************************************************************
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模式,详见:http://www.draisberghof.de/usb_modeswitch
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。详见:http://www.libusb.org/
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路径参数),详见:http://www.linuxidc.com/Linux/2011-03/33432.htm
如果复制之后仍未解决,试着添加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
...
*********************************************************
配置完之后,进行编译。输入make或者make intall,将出现如下error信息:
**************************清单4**************************
...
make  all-recursive
make[1]: Entering directory `/home/decuhi/project/New/libusb-compat-0.1.3'


Making all in libusb
make[2]: Entering directory `/home/decuhi/project/New/libusb-compat-0.1.3/libusb'
/bin/sh ../libtool --tag=CC   --mode=compile arm-linux-gcc -DHAVE_CONFIG_H -I. -I..    -fvisibility=hidden -std=gnu99  -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow -I/opt/crosstool/arm-linux/gcc-3.4.4-glibc-2.3.5/arm-linux/arm-linux//include/libusb-1.0   -g -O2 -MT libusb_la-core.lo -MD -MP -MF .deps/libusb_la-core.Tpo -c -o libusb_la-core.lo `test -f 'core.c' || echo './'`core.c
libtool: compile:  arm-linux-gcc -DHAVE_CONFIG_H -I. -I.. -fvisibility=hidden -std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow -I/opt/crosstool/arm-linux/gcc-3.4.4-glibc-2.3.5/arm-linux/arm-linux//include/libusb-1.0 -g -O2 -MT libusb_la-core.lo -MD -MP -MF .deps/libusb_la-core.Tpo -c core.c  -fPIC -DPIC -o .libs/libusb_la-core.o
cc1: error: unrecognized command line option "-Wno-pointer-sign"
cc1: error: unrecognized command line option "-fvisibility=hidden"
make[2]: *** [libusb_la-core.lo] Error 1
make[2]: Leaving directory `/home/decuhi/project/New/libusb-compat-0.1.3/libusb'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/decuhi/project/New/libusb-compat-0.1.3'
make: *** [all] Error 2
...
*********************************************************

记得当时是太相信google了,半天都没找到答案,后来百度一下才找到,很无语的说。
说是编译器版本太低的缘故。在高版本里面才支持"-Wno-pointer-sign"、"-fvisibility=hidden"。
后 来使用PC上的编译器(gcc版本4.4.1,而arm-linux-gcc是3.4.4)试了一下,就没出现这个错误,由此可推断确实是编译器版本问 题。既然低版本没有这个指令,我就删掉libusb-compat-0.1.3/libusb/Makefile里面的"-Wno-pointer- sign"和"-fvisibility=hidden",之后OK(如果其他Makefile也有,也要删)。编完之后也要将库和头文件复制到工具链里 面去。
这部分解决之后,后面就轻松了。
 
/*
 *usb_modeswitch
 */
交叉编译usb_modeswitch时,需修改下Makefile
将第3、4行的
3 STRIP       = strip
4 CC          = gcc
改成
3 STRIP       = arm-linux-strip
4 CC          = arm-linux-gcc
 
make之后会在当前目录下生成usb_modeswitch的二进制文件。
 
===========
关于usbutils,有个令我不得不记录的可恨回忆:
当时交叉编译时没设定安装路径,不小心安装到系统上。当时想先彻底删除掉这个工具,然后再安装。因为系统是自带usbutils工具的,所以在终端上输入sudo apt-get remove usbutils,之后冒出一大堆信息

正在读取软件包列表... 完成

正在分析软件包的依赖关系树

正在读取状态信息... 完成

下列软件包将被【卸载】:

checkbox checkbox-gtk gnome-mount gnome-power-manager hal hal-cups-utils lshw network-manager network-manager-gnome Ubuntu-desktop ubuntu-standard update-notifier usbutils xorg xserver-xorg xserver-xorg-core xserver-xorg-input-all xserver-xorg-input-evdev xserver-xorg-input-kbd xserver-xorg-input-mouse xserver-xorg-input-synaptics xserver-xorg-input-vmmouse xserver-xorg-input-wacom xserver-xorg-video-all xserver-xorg-video-apm xserver-xorg-video-ark xserver-xorg-video-ati xserver-xorg-video-chips xserver-xorg-video-cirrus xserver-xorg-video-fbdev xserver-xorg-video-geode xserver-xorg-video-i128 xserver-xorg-video-i740 xserver-xorg-video-intel xserver-xorg-video-mach64 xserver-xorg-video-mga xserver-xorg-video-neomagic xserver-xorg-video-nv xserver-xorg-video-openchrome xserver-xorg-video-r128 xserver-xorg-video-radeon xserver-xorg-video-rendition xserver-xorg-video-s3 xserver-xorg-video-s3virge xserver-xorg-video-savage xserver-xorg-video-siliconmotion xserver-xorg-video-sis xserver-xorg-video-sisusb xserver-xorg-video-tdfx xserver-xorg-video-trident xserver-xorg-video-tseng xserver-xorg-video-v4l xserver-xorg-video-vesa xserver-xorg-video-vmware xserver-xorg-video-voodoo

共升级了 0 个软件包,新安装了 0 个软件包,要卸载 55 个软件包,有 0 个软件未被升级。

解压缩后将会空出 38.7MB 的空间。

您希望继续执行吗?[Y/n]

毕竟是新手,什么都不懂,之后按下Y。杯具就此产生,不仅没有图形界面,而且也上不了网。再之后,折腾半天才弄回来。

============2010-02-01

放到板子上的库只需要动态库即可,静态库可不用添加。根据usb_modeswitch的说明,他是基于libusb 0.1.12库编译生成的,所以其实只要编译Legacy release的0.1.12版本就行了,不用装什么1.0跟compat。

原文地址:https://www.cnblogs.com/GoodGoodWorkDayDayUp/p/1991165.html