November 8, 2013

How to compile Net-SNMP 5.7.2 for Windows on Linux using MinGW

Here is how to compile Net-SNMP 5.7.2 for Windows on Linux using MinGW.

In my setup, the host is Fedora Linux 19 64-bit.

1. Install MinGW:
sudo  yum install mingw32-binutils mingw32-cpp mingw32-filesystem mingw32-gcc mingw32-gcc-c++ mingw32-runtime mingw32-w32api
2. Get snmp-5.7.2 source code and untar it
3. configure it:
CC=i686-w64-mingw32-gcc ./configure --host=mingw32  --with-ar=i686-w64-mingw32-ar \
--without-perl-modules --disable-embedded-perl   \
--disable-mib-loading  --with-openssl=internal  --enable-mini-agent --with-out-transports="Callback Unix TCP" \
--disable-manuals --disable-shared
Option 1
1. Comment out RANLIB in all Makefiles
find . -name Makefile | xargs sed -i 's/^RANLIB.*/RANLIB=echo'
2.
 make -j 20 

3. Manually do ranlib
find . -name "*.a" | xargs i686-w64-mingw32-ranlib
4.
 make -j 20 
8. More manual ranlib
find . -name "*.a" | xargs i686-w64-mingw32-ranlib
5. continue to make
make -j 20
This time it should make all the way to the end. That's it.

P.S.
I tried to directly set RANLIB in Makefile to be i686-w64-mingw32-ranlib, but then it tries to ranlib the *.la files and fail. If you know a way to directly set RANLIB in Makefiles and compile successfully, please let me know by leaving a comment below.

Option 2 
1. Point ranlib to mingw ranlib in all Makefiles
mkdir -p $HOME/bin; cd $HOME/bin;
cat <<EOF >myranlib
#!/bin/sh
echo Running 686-ranlib $*
i686-w64-mingw32-ranlib  $*
exit 0;
EOF
chmod +x myranlib
ln -sf ranlib myranlib
find . -name Makefile | xargs sed -i '1s/^/PATH := $(HOME)\/bin:$(PATH)\n/'

2.
 make -j 20 

This time it should make all the way to the end. That's it.


No comments:

Post a Comment