码迷,mamicode.com
首页 > 其他好文 > 详细

libnl的移植

时间:2019-12-08 17:51:58      阅读:403      评论:0      收藏:0      [点我收藏+]

标签:target   oms   http   host   ret   basic   return   库文件   工具链   

libnl简介

libnl是为了方便应用程序使用netlink接口而开发的一个库。这个库为原始netlink消息传递以及不同的netlink,family专用接口提供了一个统一的接口。libnl2.0的API与libnl1.0的API并不兼容。如果您的应用程序不做相应调整,将可能导致不可用。
移植libnl1.1是hostapd的移植的一部分。hostapd使用的libnl库为1.x版本,2.0版本的API与1.0的并不兼容,故这里移植1.1版本,但2.0移植方式相同。

开发环境

Ubuntu 18.04
arm-linux-gnueabi-gcc version 4.8.3

开发环境不一定是我这配置,只要是Linux操作系统,和ARM对应的交叉工具链就可以。

目标环境

讯为,三星4412(Cotex A9)
内核版本:4.6.1

移植步骤

  1. 从libnl官网下载libnl-1.1.4源码。
  2. 执行下面命名解压缩:tar zxvf libnl-1.1.4.tar.gz
  3. 进入刚解压的目录cd libnl-1.1.4,执行下面指令,做相应的配置:

sudo ./configure --host=arm-linux --prefix=$(pwd)/__install --enable-static --enable-shared CC=/usr/arm/arm-2014.05/bin/arm-none-linux-gnueabi-gcc

其中--prefix=$(pwd)/__install指定了编译出来的库存放的路径,我一般将其放在当前目录下的__install目录下。注意,这里的编译器指定,必须使用绝对路径,否则会报错

这里可能出现如下错误

configure: WARNING: bison not found. Please install before continuing.  
configure: WARNING: flex not found. Please install before continuing.  
configure: error: Required packages are missing. Please install them and rerun ./configure 

解决方法

sudo apt-get install bison  
sudo apt-get install flex  

配置成功后,看到如下输出

                                  NOTE  

 There have been some changes starting with 3.2 regarding where and how libnl  
 is being installed on the system in order to allow multiple libnl versions  
 to be installed in parallel:  

    - Headers will be installed in ${prefix}/include/libnl3, therefore  
      you will need to add "-I/usr/include/libnl3" to CFLAGS  

    - The library basename was renamed to libnl-3, i.e. the SO names become  
      libnl-3.so., libnl-route-3.so, etc.  

    - libtool versioning was assumed, to ease detection of compatible library  
      versions.  

 If you are using pkg-config for detecting and linking against the library   
 things will continue magically as if nothing every happened. If you are   
 linking manually you need to adapt your Makefiles or switch to using   
 pkg-config files.  

-------------------------------------------------------------------------------  
  1. 执行make编译:

这可能会遇到这样的错误

/usr/bin/ld: lib/.libs/libnl_3_la-addr.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: lib/.libs/libnl_3_la-addr.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: lib/.libs/libnl_3_la-addr.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: lib/.libs/libnl_3_la-addr.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: lib/.libs/libnl_3_la-addr.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: lib/.libs/libnl_3_la-addr.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: lib/.libs/libnl_3_la-addr.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: lib/.libs/libnl_3_la-addr.o: Relocations in generic ELF (EM: 40)
lib/.libs/libnl_3_la-addr.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
Makefile:2842: recipe for target 'lib/libnl-3.la' failed
make: *** [lib/libnl-3.la] Error 1

原因
配置那步(3.)没有做对,几乎可以肯定是编译器没有配置对,导致编译出错.

  1. 执行下面命令,将编译好的库文件拷贝到先前prefix指定的__install目录中:
    make install

成功后,在lib目录下看到下列文件

yang@yang:/usr/local/arm/libnl$ ls  
bin  etc  include  lib  share  
yang@yang:/usr/local/arm/libnl$ ls lib/  
libnl                    libnl-genl-3.so            libnl-route-3.a  
libnl-3.a                libnl-genl-3.so.200        libnl-route-3.la  
libnl-3.la               libnl-genl-3.so.200.25.0   libnl-route-3.so  
libnl-3.so               libnl-idiag-3.a            libnl-route-3.so.200  
libnl-3.so.200           libnl-idiag-3.la           libnl-route-3.so.200.25.0  
libnl-3.so.200.25.0      libnl-idiag-3.so           libnl-xfrm-3.a  
libnl-cli-3.a            libnl-idiag-3.so.200       libnl-xfrm-3.la  
libnl-cli-3.la           libnl-idiag-3.so.200.25.0  libnl-xfrm-3.so  
libnl-cli-3.so           libnl-nf-3.a               libnl-xfrm-3.so.200  
libnl-cli-3.so.200       libnl-nf-3.la              libnl-xfrm-3.so.200.25.0  
libnl-cli-3.so.200.25.0  libnl-nf-3.so              pkgconfig  
libnl-genl-3.a           libnl-nf-3.so.200  
libnl-genl-3.la          libnl-nf-3.so.200.25.0  
  1. include下文件在编译程序的时候会用到,而lib下在程序运行时会用到。故在移植hostapd的时候需要指定include的路径,需要将lib下文件拷贝到开发板中。
    lib中的可执行文件,libnl-3.so.200.25.0、libnl-genl-3.so.200.25.0放到开发板的/lib目录,

使用file filename可以查看文件版本信息,来确定是否编译正确,使用file命令可以看到如下信息

libnl-3.so.200.26.0:      ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, with debug_info, not stripped
libnl-genl-3.so.200.26.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, with debug_info, not stripped

OKey 它被编译为ARM版本,我们可以将它放到我们的ARM开发板中了

放到开发板的的/lib目录,并创建软链接

ln -s libnl-3.so.200.25.0 libnl-3.so  
ln -s libnl-3.so.200.25.0 libnl-3.so.200  
ln -s libnl-genl-3.so.200.25.0 libnl-genl-3.so  
ln -s libnl-genl-3.so.200.25.0 libnl-genl-3.so.200  

可参考:
http://www.linuxfromscratch.org/blfs/view/svn/basicnet/libnl.html

libnl的移植

标签:target   oms   http   host   ret   basic   return   库文件   工具链   

原文地址:https://www.cnblogs.com/lifo/p/12006099.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!