0%

交叉编译 libusb、libusb-compat 和 usb_modeswitch

交叉编译 libusblibusb-compat 以及 usb_modeswitch,以及之间的关系

简介

  • usb modeswitch 实现无线上网卡从 USB Storage 模式切换到 Modem 模式。usb modeswitch
  • libusblibusb-compatusb_modeswitch 需要 libusb 的支持。 libusb 分为 1.0 版0.1 版 两种版本, 1.0 并不向下兼容 0.1,需要 libusb-compat 的支持

编译

交叉编译 libusb -> libusb-compat -> usb_modeswitch

设置变量用于编译链接

PKG_CONFIG_PATH=$(INST_DIR)/lib/pkgconfig
export PKG_CONFIG_PATH

libusb

./configure --host=$(HOST) --disable-udev --prefix=$(INST_DIR) ac_cv_func_gettimeofday=yes
make
make install

安装完成后有如下信息

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

结构

$ tree
.
├── bin
│   └── libusb-config
├── include
│   ├── libusb-1.0
│   │   └── libusb.h
│   └── usb.h
└── lib
    ├── libusb-1.0.a
    ├── libusb-1.0.la
    ├── libusb.a
    ├── libusb.la
    └── pkgconfig
        ├── libusb-1.0.pc
        └── libusb.pc

当编译后续包时需要依赖已交叉编译的包

libusb-compat

./configure LDFLAGS="-L$(INST_DIR)/lib $(CONFIG_EXTRA_FLAGS)" --host=$(HOST) --prefix=$(INST_DIR)
make
make install

usb_modeswitch

make $J CC=$(CONFIG_CROSS_COMPILE)gcc   LDFLAGS="-L$(INST_DIR)/lib -lusb-1.0 -static -lpthread $(CONFIG_EXTRA_FLAGS)" CFLAGS="-I$(INST_DIR)/include/libusb-1.0 $(CONFIG_EXTRA_FLAGS)"