Discussion:
How to create statically linked net-snmp binaries
Richard Wall
17 years ago
Permalink
Hi,

I've been trying to compile a statically linked snmpd binary with
net-snmp-5.4.1 and on Ubuntu Gutsy.
I used the configure options described in the FAQ and in another
mailing list post:
* http://net-snmp.sourceforge.net/wiki/index.php/FAQ:Compiling_06
* http://www.avr32linux.org/twiki/bin/view/Main/Net-SNMP

Relevant options were:
--with-ldflags=-Bstatic
--disable-shared
--enable-static

...but ldd snmpd still reports:

$ ldd agent/snmpd
linux-gate.so.1 => (0xffffe000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7f7e000)
libcrypto.so.0.9.8 => /usr/lib/i686/cmov/libcrypto.so.0.9.8 (0xb7e3b000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7cf0000)
/lib/ld-linux.so.2 (0xb7f95000)
libz.so.1 => /usr/lib/libz.so.1 (0xb7cdb000)

Can anyone advise me whether they have successfully managed to
statically compile a recent net-snmp? Perhaps there's something
obvious that I'm missing.

Thanks in advance to anyone who can help.

-RichardW.

Entire configure command was:
./configure --enable-mini-agent \
--with-default-snmp-version=3 \
--with-sys-contact="***@emailaddress.com" \
--with-sys-location=Home \
--with-logfile=/var/log/snmpd.log \
--with-persistent-directory=/var/net-snmp \
--disable-shared \
--enable-static \
--disable-applications \
--without-rpm \
--without-dmalloc \
--without-efence \
--without-rsaref \
--enable-mini-agent \
--with-defaults \
--prefix=/usr \
--sysconfdir=/etc \
--disable-manuals \
--disable-debugging \
--disable-scripts \
--disable-mibs \
--disable-mib-loading \
--disable-ipv6 \
--with-mib-modules="snmpv3mibs host smux ucd-snmp/proc
ucd-snmp/loadave ucd-snmp/memory ucd-snmp/vmstat ucd-snmp/dlmod
agent_mibs agentx target" \
--with-ldflags=-Bstatic
--
Richard Wall
http://www.appliansys.com
Dave Shield
17 years ago
Permalink
Post by Richard Wall
I've been trying to compile a statically linked snmpd binary with
net-snmp-5.4.1 and on Ubuntu Gutsy.
$ ldd agent/snmpd
linux-gate.so.1 => (0xffffe000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7f7e000)
libcrypto.so.0.9.8 => /usr/lib/i686/cmov/libcrypto.so.0.9.8 (0xb7e3b000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7cf0000)
/lib/ld-linux.so.2 (0xb7f95000)
libz.so.1 => /usr/lib/libz.so.1 (0xb7cdb000)
The first thing that springs out about that list is that it doesn't mention
any of the Net-SNMP libraries. So you are successfully statically
linking with *those*, at least.

Also, this list is significantly shorter than the usual list on my Fedora box
(which includes 30-odd libraries).

So I suspect that you *are* statically linking as much as possible.
My guess is that the libraries listed above are the ones where the
static (.a) version is not installed on your system. So the agent
has linked against the dynamic version, 'cos there's nothing else
to use.

I'm not sure how Ubuntu/Debian structures its packages, but if there
are '-devel' versions of the relevant packages, it might be worth
installing those, and re-compiling the agent.

Dave
Richard Wall
17 years ago
Permalink
...
Thanks Dave,

Actually, I was about to email the list to say that I did manage to
create an entirely self contained binary.

Trick is to manually run the last gcc command reported by make,
appending the argument -static. So you do:

make agent

...when its finished you change to the agent subfolder and run gcc
with argument -static...

gcc -static -Ulinux -Dlinux=linux -o snmpd snmpd.o
-L/home/richard/src/net-snmp-5.4.1/agent/.libs

...which produces various warnings...

/home/richard/src/net-snmp-5.4.1/snmplib/.libs/libnetsnmp.a(snmpv3.o):
In function `setup_engineID':
snmpv3.c:(.text+0xcef): warning: Using 'gethostbyname' in statically
linked applications requires at runtime the shared libraries from the
glibc version used for linking

...but results in...

ldd snmpd
not a dynamic executable

...which so far has been working well for me.

I guess the problem is in the agent Makefile, but I haven't had a
chance to look very closely.

-RichardW.
--
Richard Wall
http://www.appliansys.com
Loading...