iptables1.8.10移植

第一步:下载iptables-1.8.10+libmnl-1.0.5+libnftnl-1.2.7

iptables下载地址:https://www.netfilter.org/projects/iptables/downloads.html 

libmnl下载地址:Index of /pub/libmnl

libnftnl下载地址:Index of /pub/libnftnl

第二步:交叉编译,以arm-rockchip830-linux-uclibcgnueabihf-为例

将libmnl-1.0.5.tar.bz2、libnftnl-1.2.7.tar.xz、iptables-1.8.10.tar.xz放置于同一个目录中并解压。

tar -xvf libmnl-1.0.5.tar.bz2

tar -xvf libnftnl-1.2.7.tar.xz

tar -xvf iptables-1.8.10.tar.xz

2.1首先编译libmnl

cd  libmnl-1.0.5

./configure  --host=arm-rockchip830-linux-uclibcgnueabihf CC=arm-rockchip830-linux-uclibcgnueabihf-gcc  LDFLAGS=-static --prefix=$PWD/__install

make
make install

会在 libmnl-1.0.5文件夹中出现__install为安装目录

2.2编译libnftnl,需要使用libmnl的编译输出文件

cd  libmnl-1.0.5

mkdir third && cp ../libmnl-1.0.5/__install* third/ -rf 
./configure  --host=arm-rockchip830-linux-uclibcgnueabihf CC=arm-rockchip830-linux-uclibcgnueabihf-gcc LDFLAGS=-static --prefix=$PWD/__install  \
LIBMNL_CFLAGS=-Ixxxxx/libnftnl-1.2.7/third/include  \
LIBMNL_LIBS=xxxxx/libnftnl-1.2.7/third/lib

make
make install

会在 libnftnl-1.2.7文件夹中出现__install为安装目录

2.3编译iptables ,需要使用libmnl和libnftnl的编译输出文件

cd  iptables-1.8.10

mkdir third && cp ../libmnl-1.0.5/__install* third/ -rf  &&  cp ../libnftnl-1.2.7/__install* third/ -rf 

./configure --host=arm-rockchip830-linux-uclibcgnueabihf CC=arm-rockchip830-linux-uclibcgnueabihf-gcc --enable-static --disable-shared --prefix=$PWD/__install \
PKG_CONFIG=/usr/bin/pkg-config  \
libmnl_CFLAGS=-I******/iptables-1.8.10/third/include  \
libnftnl_CFLAGS=-I******/iptables-1.8.10/third/include  \
libmnl_LIBS=******/iptables-1.8.10/third/lib/libmnl.a   \
libnftnl_LIBS=******/iptables-1.8.10/third/lib/libnftnl.a  

注:******为iptables-1.8.10的绝对路径

make
make install

会在 iptables-1.8.10文件夹中出现__install为安装目录

说明:

1.可使用./configure --help  或则./configure -h 来查看设置选项。

2.在./configure 选项不正确的时候,会出现以下报错:

libnftnl configure  报错1

checking whether make supports nested variables... (cached) yes

checking pkg-config is at least version 0.9.0... yes

checking for libmnl >= 1.0.4... no

configure: error: Package requirements (libmnl >= 1.0.4) were not met:

No package 'libmnl' 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 LIBMNL_CFLAGS

and LIBMNL_LIBS to avoid the need to call pkg-config.

See the pkg-config man page for more details.

libnftnl configure  报错2

make  all-recursive

make[1]: 进入目录“/home/ztt/share/test/iptables-1.8.10/libnftnl-1.2.7”

Making all in src

make[2]: 进入目录“/home/ztt/share/test/iptables-1.8.10/libnftnl-1.2.7/src”

  CC       batch.lo

batch.c:12:10: fatal error: libmnl/libmnl.h: No such file or directory

 #include <libmnl/libmnl.h>

          ^~~~~~~~~~~~~~~~~

compilation terminated.

make[2]: *** [Makefile:711:batch.lo] 错误 1

make[2]: 离开目录“/home/ztt/share/test/iptables-1.8.10/libnftnl-1.2.7/src”

make[1]: *** [Makefile:495:all-recursive] 错误 1

make[1]: 离开目录“/home/ztt/share/test/iptables-1.8.10/libnftnl-1.2.7”

iptables configure  报错1

checking for libmnl >= 1.0... no

*** Error: No suitable libmnl found. ***

    Please install the 'libmnl' package

    Or consider --disable-nftables to skip

iptables-compat over nftables support.

iptables configure  报错2

checking for libmnl >= 1.0... yes

checking for libnftnl >= 1.2.6... no

*** Error: no suitable libnftnl found. ***

    Please install the 'libnftnl' package

    Or consider --disable-nftables to skip

    iptables-compat over nftables support

3.排错方法:

查看configure文件:有以下内容:

if test -n "$libnftnl_CFLAGS"; then
    pkg_cv_libnftnl_CFLAGS="$libnftnl_CFLAGS"
 elif test -n "$PKG_CONFIG"; then
    if test -n "$PKG_CONFIG" && \
    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libnftnl >= 1.2.6\""; } >&5
  ($PKG_CONFIG --exists --print-errors "libnftnl >= 1.2.6") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; then
  pkg_cv_libnftnl_CFLAGS=`$PKG_CONFIG --cflags "libnftnl >= 1.2.6" 2>/dev/null`
              test "x$?" != "x0" && pkg_failed=yes
else
  pkg_failed=yes
fi
 else
    pkg_failed=untried
fi

可以看到优先生效的libnftnl_CFLAGS等信息,后生效的PKG_CONFIG,当交叉编译链无pkg-config时或者不使用pkg-config时,可以优先设置libnftnl_CFLAGS和libnftnl_LIBS来添加库信息。

  • 25
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值