分类: LINUX
[root@localhost usb-modeswitch]# ls
libusb-1.0.1.tar.bz2 libusb-compat-0.1.5.tar.bz2 usb-modeswitch-1.2.5.tar.bz2
[root@localhost usb-modeswitch]# tar -xjflibusb-1.0.1.tar.bz2
[root@localhost usb-modeswitch]# tar -xjflibusb-compat-0.1.5.tar.bz2
[root@localhost usb-modeswitch]# tarusb-modeswitch-1.2.5.tar.bz2
[root@localhost usb-modeswitch]# tar -xjfusb-modeswitch-1.2.5.tar.bz2
[root@localhost usb-modeswitch]# ls
libusb-1.0.1 libusb-compat-0.1.5 usb-modeswitch-1.2.5
libusb-1.0.1.tar.bz2 libusb-compat-0.1.5.tar.bz2 usb-modeswitch-1.2.5.tar.bz2[root@localhostusb-modeswitch]# cd usb-modeswitch-1.2.5
[root@localhost usb-modeswitch-1.2.5]# ls
ChangeLog jim make_string.tcl usb_modeswitch.c usb_modeswitch.sh
COPYING Makefile README usb_modeswitch.conf usb_modeswitch.tcl
dispatcher.c make_static_dispatcher.sh usb_modeswitch.1 usb_modeswitch.h
[root@localhost usb-modeswitch-1.2.5]# make
gcc -o usb_modeswitch usb_modeswitch.c-Wall -l usb
usb_modeswitch.c:58:17: error: usb.h: Nosuch file or directory
In file included from usb_modeswitch.c:59:
usb_modeswitch.h:53: warning: ‘structusb_dev_handle’ declared inside parameter list
usb_modeswitch.h:53: warning: its scope isonly this definition or declaration, which is probably not what you want
usb_modeswitch.c: In function ‘main’:
usb_modeswitch.c:417: warning: implicitdeclaration of function ‘usb_init’
usb_modeswitch.c:420: warning: implicitdeclaration of function ‘usb_set_debug’
usb_modeswitch.c:422: warning: implicitdeclaration of function ‘usb_find_busses’
usb_modeswitch.c:423: warning: implicitdeclaration of function ‘usb_find_devices’
usb_modeswitch.c:454: error: dereferencingpointer to incomplete type
usb_modeswitch.c:455: error: dereferencingpointer to incomplete type
usb_modeswitch.c:458: warning: implicitdeclaration of function ‘usb_open’
usb_modeswitch.c:458: warning: assignmentmakes pointer from integer without a cast
usb_modeswitch.c:474: warning: passingargument 1 of ‘get_current_configuration’ from incompatible pointer type
usb_modeswitch.h:53: note: expected ‘structusb_dev_handle *’ but argument is of type ‘struct usb_dev_handle *’
.............................................
.............................................
这里缺少usb.h文件,需要第三方(libusb-compat-0.1.5)提供。
[root@localhost usb-modeswitch-1.2.5]# cd..
[root@localhost usb-modeswitch]# ls
libusb-1.0.1 libusb-compat-0.1.5 usb-modeswitch-1.2.5
libusb-1.0.1.tar.bz2 libusb-compat-0.1.5.tar.bz2 usb-modeswitch-1.2.5.tar.bz2
[root@localhost usb-modeswitch]# cdlibusb-compat-0.1.5
[root@localhost libusb-compat-0.1.5]# ls
aclocal.m4 compile config.sub COPYING INSTALL libusb-config.in ltmain.sh Makefile.in README
AUTHORS config.guess configure depcomp install-sh libusb.pc.in m4 missing
ChangeLog config.h.in configure.ac examples libusb LICENSE Makefile.am NEWS
[root@localhost libusb-compat-0.1.5]#./configure --help
`configure' configures libusb-compat 0.1.5to adapt to many kinds of systems.
Usage: ./configure [OPTION]...[VAR=VALUE]...
To assign environment variables (e.g., CC,CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified inbrackets.
Configuration:
-h,--help display this help andexit
--help=short displayoptions specific to this package
--help=recursive display theshort help of all the included packages
-V,--version display versioninformation and exit
-q,--quiet, --silent do not print`checking ...' messages
--cache-file=FILE cache testresults in FILE [disabled]
-C,--config-cache alias for`--cache-file=config.cache'
-n,--no-create do not create outputfiles
.............................................
.............................................
根据查看help来移植第三方程序。
[root@localhost libusb-compat-0.1.5]# pwd
/home/tools/usb-modeswitch/libusb-compat-0.1.5
[root@localhost libusb-compat-0.1.5]#./configure --prefix=/home/tools/usb-modeswitch/install --enable-shared
checking for a BSD-compatible install.../usr/bin/install -c
checking whether build environment issane... yes
checking for a thread-safe mkdir -p.../bin/mkdir -p
checking for gawk... gawk
...............................................
...............................................
checking pkg-config is at least version0.9.0... yes
checking for LIBUSB_1_0... no
configure: error: Package requirements(libusb-1.0 >= 0.9.1) were not met:
No package 'libusb-1.0' found
Consider adjusting the PKG_CONFIG_PATHenvironment variable if you
installed software in a non-standardprefix.
Alternatively, you may set the environmentvariables LIBUSB_1_0_CFLAGS
and LIBUSB_1_0_LIBS to avoid the need tocall pkg-config.
See the pkg-config man page for moredetails.
这里说No package'libusb-1.0' found,我们要提供libusb-1.0包。
[root@localhost libusb-compat-0.1.5]# cd ..
[root@localhost usb-modeswitch]# cdlibusb-1.0.1
[root@localhost libusb-1.0.1]# ls
aclocal.m4 ChangeLog config.h.in configure.ac doc install-sh ltmain.sh missing README
AUTHORS compile config.sub COPYING examples libusb Makefile.am NEWS THANKS
BUGS config.guess configure depcomp INSTALL libusb-1.0.pc.in Makefile.in PORTING TODO
[root@localhost libusb-1.0.1]# ./configure--help
`configure' configures libusb 1.0.1 toadapt to many kinds of systems.
Usage: ./configure [OPTION]...[VAR=VALUE]...
To assign environment variables (e.g., CC,CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified inbrackets.
Configuration:
-h,--help display this help andexit
--help=short displayoptions specific to this package
...........................................
...........................................
同样查看help。
[root@localhost libusb-1.0.1]# ./configure--prefix=/home/tools/usb-modeswitch/install --enable-shared
[root@localhost libusb-1.0.1]# make
[root@localhost libusb-1.0.1]# make install
[root@localhost libusb-1.0.1]# cd ../
[root@localhost usb-modeswitch]# ls
install libusb-1.0.1.tar.bz2 libusb-compat-0.1.5.tar.bz2 usb-modeswitch-1.2.5.tar.bz2
libusb-1.0.1 libusb-compat-0.1.5 usb-modeswitch-1.2.5
[root@localhost usb-modeswitch]# cdlibusb-compat-0.1.5
[root@localhost libusb-compat-0.1.5]#./configure --prefix=/home/tools/usb-modeswitch/install --enable-sharedPKG_CONFIG_PATH=/home/tools/usb-modeswitch/libusb-1.0.1
checking for a BSD-compatible install.../usr/bin/install -c
checking whether build environment issane... yes
checking for a thread-safe mkdir -p.../bin/mkdir -p
checking for gawk... gawk
.................................
.................................
[root@localhost libusb-1.0.1]# make
[root@localhost libusb-1.0.1]# make install
[root@localhost libusb-compat-0.1.5]# cd ..
[root@localhost usb-modeswitch]# cdusb-modeswitch-1.2.5
[root@localhost usb-modeswitch-1.2.5]# ls
ChangeLog jim make_string.tcl usb_modeswitch.c usb_modeswitch.sh
COPYING Makefile README usb_modeswitch.conf usb_modeswitch.tcl
dispatcher.c make_static_dispatcher.sh usb_modeswitch.1 usb_modeswitch.h
[root@localhost usb-modeswitch-1.2.5]#export CFLAGS="-I /home/tools/usb-modeswitch/install/include"
[root@localhost usb-modeswitch-1.2.5]#export LDFLAGS="-L /home/tools/usb-modeswitch/install/lib"
[root@localhost usb-modeswitch-1.2.5]# make
gcc -o usb_modeswitch usb_modeswitch.c -I/home/tools/usb-modeswitch/install/include/ -Wall -l usb -L/home/tools/usb-modeswitch/install/lib
[root@localhost usb-modeswitch-1.2.5]# fileusb_modeswitch
usb_modeswitch: ELF 32-bit LSB executable,Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), forGNU/Linux 2.6.18, not stripped
现在移植的是x86体系结构下的usb_modeswitch,但需要的是arm体系结构下的。
修改Makefile
[root@localhost usb-modeswitch-1.2.5]# vimMakefile
[root@localhost usb-modeswitch-1.2.5]# head-8 Makefile
PROG = usb_modeswitch
VERS = 1.2.5
//CC = gcc
CC =/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
CFLAGS += -Wall
LIBS = -l usb
RM = /bin/rm -f
OBJS = usb_modeswitch.c
[root@localhost usb-modeswitch-1.2.5]# makeclean
/bin/rm -f usb_modeswitch
/bin/rm -f usb_modeswitch_dispatcher
/bin/rm -f usb_modeswitch.string
[root@localhost usb-modeswitch-1.2.5]# make
/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc -o usb_modeswitch usb_modeswitch.c -I/home/tools/usb-modeswitch/install/include/ -Wall -l usb -L/home/tools/usb-modeswitch/install/lib
/opt/buildroot-2012.08/arm920t/usr/lib/gcc/arm-unknown-linux-uclibcgnueabi/4.5.4/../../../../arm-unknown-linux-uclibcgnueabi/bin/ld:skipping incompatible /home/tools/usb-modeswitch/install/lib/libusb.so whensearching for -lusb
/opt/buildroot-2012.08/arm920t/usr/lib/gcc/arm-unknown-linux-uclibcgnueabi/4.5.4/../../../../arm-unknown-linux-uclibcgnueabi/bin/ld:skipping incompatible /home/tools/usb-modeswitch/install/lib/libusb.a whensearching for -lusb
/opt/buildroot-2012.08/arm920t/usr/lib/gcc/arm-unknown-linux-uclibcgnueabi/4.5.4/../../../../arm-unknown-linux-uclibcgnueabi/bin/ld:cannot find -lusb
collect2: ld returned 1 exit status
make: *** [usb_modeswitch] Error 1
现在虽然指定了交叉编译器,但提供的库任然是x86结构下的,所以要重新编译libusb-compat-0.1.5,libusb-1.0,提供arm体系结构下的库。
[lingyun@localhost usb_modeswitch]$ ls
libusb-1.0.1.tar.bz2 libusb-compat-0.1.5.tar.bz2 usb-modeswitch-1.2.5.tar.bz2
[lingyun@localhost usb_modeswitch]$ tar-xjf libusb-1.0.1.tar.bz2
[lingyun@localhost usb_modeswitch]$ tar-xjf libusb-compat-0.1.5.tar.bz2
[lingyun@localhost usb_modeswitch]$ tar-xjf usb-modeswitch-1.2.5.tar.bz2
[lingyun@localhost usb_modeswitch]$ cdlibusb-1.0.1
[lingyun@localhost libusb-1.0.1]$ ls
aclocal.m4 ChangeLog config.h.in configure.ac doc install-sh ltmain.sh missing README
AUTHORS compile config.sub COPYING examples libusb Makefile.am NEWS THANKS
BUGS config.guess configure depcomp INSTALL libusb-1.0.pc.in Makefile.in PORTING TODO
[lingyun@localhost libusb-1.0.1]$exportCC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
[lingyun@localhost libusb-1.0.1]$exportCXX=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-g++
[lingyun@localhost libusb-1.0.1]$exportAR=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar
[lingyun@localhost libusb-1.0.1]$exportAS=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-as
[lingyun@localhost libusb-1.0.1]$exportLD=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ld
[lingyun@localhost libusb-1.0.1]$exportSTRIP=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-strip
[lingyun@localhost libusb-1.0.1]$exportRANLIB=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib
[lingyun@localhost libusb-1.0.1]$exportnm=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-nm
[lingyun@localhost libusb-1.0.1]$./configure --prefix=/home/lingyun/caijie/tools/usb_modeswitch/install--disable-shared --enable-static --build=arm --host=arm-linux
[lingyun@localhost libusb-1.0.1]$ make
[lingyun@localhost libusb-1.0.1]$ makeinstall
[lingyun@localhost usb_modeswitch]$ cdlibusb-compat-0.1.5
[lingyun@localhost libusb-compat-0.1.5]$ ls
aclocal.m4 compile config.sub COPYING INSTALL libusb-config.in ltmain.sh Makefile.in README
AUTHORS config.guess configure depcomp install-sh libusb.pc.in m4 missing
ChangeLog config.h.in configure.ac examples libusb LICENSE Makefile.am NEWS
[lingyun@localhostlibusb-1.0.1]$./configure --prefix=/home/lingyun/caijie/tools/usb_modeswitch/install--disable-shared --enable-static --build=arm --host=arm-linux PKG_CONFIG_PATH=/home/lingyun/caijie/tools/usb_modeswitch/libusb-1.0.1
[lingyun@localhost libusb-1.0.1]$ make
[lingyun@localhost libusb-1.0.1]$ makeinstall
[lingyun@localhost usb-modeswitch-1.2.5]$exportCFLAGS="-I/home/lingyun/caijie/tools/usb_modeswitch/install/include"
[lingyun@localhost usb-modeswitch-1.2.5]$exportLDFLAGS="-L/home/lingyun/caijie/tools/usb_modeswitch/install/lib"
[lingyun@localhost usb-modeswitch-1.2.5]$make
gcc -o usb_modeswitch usb_modeswitch.c-I/home/lingyun/caijie/tools/usb_modeswitch/install/include -Wall -l usb-L/home/lingyun/caijie/tools/usb_modeswitch/install/lib
/usr/bin/ld: skipping incompatible/home/lingyun/caijie/tools/usb_modeswitch/install/lib/libusb.a when searchingfor -lusb
/usr/bin/ld: cannot find -lusb
collect2: ld returned 1 exit status
make: *** [usb_modeswitch] Error 1
修改Makefile
sed -i -e "s|^CC.*|CC = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc|g"Makefile
sed -i -e "s|^CFLAGS.*|CFLAGS += -Wall -I../install/include-static|g" Makefile
sed -i -e "s|^LIBS.*|LIBS = -L../install/lib/ -l usb -l usb-1.0-l pthread|g" Makefile
[lingyun@localhost usb-modeswitch-1.2.5]$make
/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc-o usb_modeswitch usb_modeswitch.c-I/home/lingyun/caijie/tools/usb_modeswitch/install/include -Wall-I../install/include -static -L../install/lib/ -l usb -l usb-1.0 -l pthread-L/home/lingyun/caijie/tools/usb_modeswitch/install/lib
[lingyun@localhost usb-modeswitch-1.2.5]$ls
ChangeLog jim make_string.tcl usb_modeswitch.1 usb_modeswitch.h
COPYING Makefile README usb_modeswitch.c usb_modeswitch.sh
dispatcher.c make_static_dispatcher.sh usb_modeswitch usb_modeswitch.conf usb_modeswitch.tcl
[lingyun@localhost usb-modeswitch-1.2.5]$file usb_modeswitch
usb_modeswitch: ELF 32-bit LSB executable,ARM, version 1 (SYSV), statically linked, not stripped