【交叉编译】--利用树莓派交叉编译工具编译snmp源码

开发环境:ubuntu16.04

cpu架构:x86

交叉编译工具 gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xz

下载地址:https://www.linaro.org/downloads/

将交叉编译工具bin目录加到PATH环境变量里

export $PATH=$PATH:/home/guo/Downloads/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin:

 

net-snmp  

下载地址

http://www.net-snmp.org/download.html

解压net-snmp

tar xf net-snmp-5.7.3.tar.gz
cd net-snmp-5.7.3/

创建安装目录

mkdir /mnt/snmp

利用configure文件生成Makefile文件

./configure --prefix=/mnt/snmp --host=x86_64 --target=arm-linux --with-cc=arm-linux-gnueabihf-gcc --with-ar=arm-linux-gnueabihf-ar --with--endianness=little --enable-mfd-rewrites --with-default-snmp-version="3" --with-sys-contact="guo@126.com" --with-sys-location="China" --with-logfile="/var/log/snmp.log" --with-persistent-directory="/var/net-snmp"
configure: WARNING: unrecognized options: --with--endianness
checking what to build and install...  agent apps man local mibs
using default persistent mask 077
using default temporary file pattern /tmp/snmpdXXXXXX
using default AgentX socket /var/agentx/master
using default "enterprise.net-snmp"
using default enterprise sysOID "NET-SNMP-MIB::netSnmpAgentOIDs..."
using default notifications "NET-SNMP-MIB::netSnmpNotifications"
using OS default send buffer size for server sockets
using OS default recv buffer size for server sockets
using OS default send buffer size for client sockets
using OS default recv buffer size for client sockets
checking Default version of SNMP to use... (cached) 2
checking System Contact Information... (cached) raining@126.com
checking System Location... (cached) China
checking Location to write logfile... (cached) /var/log/snmp.log
checking Location to write persistent information... (cached) /var/net-snmp
checking if I need to feed myself to ksh... no
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for grep that handles long lines and -e... (cached) /bin/grep
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln -s works... yes
checking whether make sets $(MAKE)... yes
checking for a sed that does not truncate output... /bin/sed
checking for file... file
checking for find... find
checking for whoami... whoami
checking for autoconf... /usr/bin/autoconf
checking for autoheader... /usr/bin/autoheader
checking for perl... /usr/bin/perl
checking for ps... /bin/ps
checking for python... /usr/bin/python
checking for uname... /bin/uname
checking whether the Perl function system() invokes a POSIX shell... yes
checking for gcc... arm-linux-gnueabihf-gcc
checking whether the C compiler works... no
configure: error: in `/home/trust100/Downloads/net-snmp-5.7.3':
configure: error: C compiler cannot create executables
See `config.log' for more details

报了一个错,说是c编译器不能创建执行命令

可以通过 see config.log查看

see config.log

翻到最后一页,发现其中影响的参数有LIBS、CFLAGS、LDFLAGS,我们将它清空试试看

解决方法

export LIBS=
export CFLAGS=
export LDFLAGS=

重新./configure试试



./configure --prefix=/mnt/snmp --host=x86_64  --target=arm-linux --with-cc=arm-linux-gnueabihf-gcc --with-ar=arm-linux-gnueabihf-ar --with--endianness=little --enable-mfd-rewrites --with-default-snmp-version="3" --with-sys-contact="guo@126.com" --with-sys-location="China" --with-logfile="/var/log/snmp.log" --with-persistent-directory="/var/net-snmp"

发现可以了

configure: WARNING: unrecognized options: --with--endianness
configure: WARNING: if you wanted to set the --build type, don't use --host.
    If a cross compiler is detected then cross compile mode will be used
checking what to build and install...  agent apps man local mibs
using default persistent mask 077
using default temporary file pattern /tmp/snmpdXXXXXX
using default AgentX socket /var/agentx/master
using default "enterprise.net-snmp"
using default enterprise sysOID "NET-SNMP-MIB::netSnmpAgentOIDs..."
using default notifications "NET-SNMP-MIB::netSnmpNotifications"
using OS default send buffer size for server sockets
using OS default recv buffer size for server sockets
using OS default send buffer size for client sockets
using OS default recv buffer size for client sockets
checking Default version of SNMP to use... (cached) 3
checking System Contact Information... (cached) raining@126.com
checking System Location... (cached) China
checking Location to write logfile... (cached) /var/log/snmp.log
checking Location to write persistent information... (cached) /var/net-snmp
checking if I need to feed myself to ksh... no
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for grep that handles long lines and -e... (cached) /bin/grep
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln -s works... yes
checking whether make sets $(MAKE)... yes
checking for a sed that does not truncate output... /bin/sed
checking for file... file
checking for find... find
checking for whoami... whoami
checking for autoconf... /usr/bin/autoconf
checking for autoheader... /usr/bin/autoheader
checking for perl... /usr/bin/perl
checking for ps... /bin/ps
checking for python... /usr/bin/python
checking for uname... /bin/uname
checking whether the Perl function system() invokes a POSIX shell... yes
checking for root-gcc... arm-linux-gnueabihf-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-linux-gnueabihf-gcc accepts -g... yes
checking for arm-linux-gnueabihf-gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... arm-linux-gnueabihf-gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
......

紧接着,编译  make -j4

make -j4

然后安装 make install 

make install 
arm-linux-gnueabihf-gcc -E -Iinclude -I./include -I./agent/mibgroup -I. -I. -DDONT_INC_STRUCTS -DBINDIR=/mnt/snmp/bin -x c ./sedscript.in | egrep '^s[/#]' | sed 's/REMOVEME//g;s# */#/#g;s/ *#/#/g;s#/ *#/#g;s/# g/#g/;' > sedscript
chmod a+x net-snmp-config
making all in /home/trust100/Downloads/net-snmp-5.7.3/snmplib
touch net-snmp-config-x
echo 's/VERSIONINFO/5.7.3/g' >> sedscript
echo 's#DATADIR#/mnt/snmp/share#g' >> sedscript
echo 's#LIBDIR#/mnt/snmp/lib#g' >> sedscript
echo 's#BINDIR#/mnt/snmp/bin#g' >> sedscript
echo 's#PERSISTENT_DIRECTORY#/var/net-snmp#g' >> sedscript
echo 's#SYSCONFDIR#/mnt/snmp/etc#g' >> sedscript
make[1]: Entering directory '/home/trust100/Downloads/net-snmp-5.7.3/snmplib'
/bin/sed -f sedscript ./EXAMPLE.conf.def > EXAMPLE.conf
/bin/bash ../libtool  --mode=compile arm-linux-gnueabihf-gcc -I../include -I. 	-I../snmplib  -fno-strict-aliasing  -Ulinux -Dlinux=linux  -c -o snmp_client.lo snmp_client.c
......

查看安装目录,我的安装目录在/mnt/snmp

root@ubuntu:/mnt/snmp# ls
bin  include  lib  sbin  share
root@ubuntu:/mnt/snmp# cd sbin
root@ubuntu:/mnt/snmp/sbin# ls
snmpd  snmptrapd
root@ubuntu:/mnt/snmp/sbin# file snmpd
snmpd: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 2.6.32, BuildID[sha1]=5f5996a87af8d514fdf74714f04f8156ff5465b5, not stripped

 

参与评论 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:撸撸猫 设计师:马嘣嘣 返回首页

打赏作者

GLL_

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值