Ajith Adapa | 27 May 2012 14:38
Picon

Building tcpdump with static libraries

Hi,

Can I know how to build tcpdump with static libraries rather than with
shared libraries ?

Regards,
Ajith
--------------------------------------------
codingfreak.in <http://www.codingfreak.in>
kielaka | 27 May 2012 17:29
Picon
Favicon

Re: Building tcpdump with static libraries

Użytkownik Ajith Adapa <adapa.ajith <at> gmail.com> napisał:
>Hi,
>
>Can I know how to build tcpdump with static libraries rather than with
>shared libraries ?
>
>Regards,
>Ajith
>--------------------------------------------
>codingfreak.in <http://www.codingfreak.in>
>-
>This is the tcpdump-workers list.
>Visit https://cod.sandelman.ca/ to unsubscribe.
>

I think that is default kind library, when You use Makefile generated from ./configure  (from source:  git
clone git://bpf.tcpdump.org/tcpdump). 
Ajith Adapa | 28 May 2012 04:40
Picon

Re: Building tcpdump with static libraries

Thanks for the reply,

I have generated Makefile from ./configure and doing a tcpdump build.

Now if I build tcpdump it is linked with shared libraries of libpcap and
others as shown below. Is it possible for me to create tcpdump binary
linking up with all static libraries ?

$ ldd tcpdump
    linux-gate.so.1 =>  (0x00816000)
    libcrypto.so.0.9.8 => /lib/i686/cmov/libcrypto.so.0.9.8 (0x00b95000)
    libpcap.so.0.8 => /usr/lib/libpcap.so.0.8 (0x002c9000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00110000)
    libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00340000)
    libz.so.1 => /lib/libz.so.1 (0x00398000)
    /lib/ld-linux.so.2 (0x008c1000)

Regards,
Ajith
--------------------------------------------
codingfreak.in <http://www.codingfreak.in>

On Sun, May 27, 2012 at 8:59 PM, <kielaka <at> vp.pl> wrote:

> Użytkownik Ajith Adapa <adapa.ajith <at> gmail.com> napisał:
> >Hi,
> >
> >Can I know how to build tcpdump with static libraries rather than with
> >shared libraries ?
> >
(Continue reading)

Guy Harris | 28 May 2012 10:14
Picon
Favicon

Re: Building tcpdump with static libraries


On May 27, 2012, at 7:40 PM, Ajith Adapa wrote:

> Now if I build tcpdump it is linked with shared libraries of libpcap and
> others as shown below. Is it possible for me to create tcpdump binary
> linking up with all static libraries ?

You would have to modify the Makefile by hand to statically link tcpdump; the way that would be done is
platform-specific - as you're building on Linux, adding "-static" to the line that links tcpdump should
suffice.  (You will, of course, have to make sure that static versions of all those libraries are installed
on your system; I think that, on the major Linux distributions, the header files needed to compile
programs using a library and the static version of that library are in a "{libraryname}-dev" package, or
something such as that, so if you have the headers that allowed you to compile tcpdump in the first place,
you probably also have the static versions of the libraries with which you need to link tcpdump.)

Also, if libpcap *itself* depends on libraries other than libc - try runnning "ldd
/usr/lib/libpcap.so.0.8" to see what libraries it requires - and tcpdump isn't itself being linked with
them by the Makefile - you will have to modify the link command in the Makefile to link with them.-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.

Artur Kielak | 28 May 2012 08:31
Picon
Favicon

Re: Building tcpdump with static libraries

> Thanks for the reply,
> 
> I have generated Makefile from ./configure and doing a tcpdump build.
> 
> Now if I build tcpdump it is linked with shared libraries of libpcap and
> others as shown below. Is it possible for me to create tcpdump binary
> linking up with all static libraries ?
> 
> $ ldd tcpdump
>     linux-gate.so.1 =>  (0x00816000)
>     libcrypto.so.0.9.8 => /lib/i686/cmov/libcrypto.so.0.9.8 (0x00b95000)
>     libpcap.so.0.8 => /usr/lib/libpcap.so.0.8 (0x002c9000)
>     libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00110000)
>     libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00340000)
>     libz.so.1 => /lib/libz.so.1 (0x00398000)
>     /lib/ld-linux.so.2 (0x008c1000)
> 
> 
> Regards,
> Ajith
> --------------------------------------------
> codingfreak.in <http://www.codingfreak.in>
> 
> 
> On Sun, May 27, 2012 at 8:59 PM, <kielaka <at> vp.pl> wrote:
> 
> > Użytkownik Ajith Adapa <adapa.ajith <at> gmail.com> napisał:
> > >Hi,
> > >
> > >Can I know how to build tcpdump with static libraries rather than with
(Continue reading)

Ajith Adapa | 28 May 2012 09:05
Picon

Re: Building tcpdump with static libraries

Hi,

Thanks for the reply - Artur Kielak

Actually I cloned the from git repository - git://github.com/mcr/tcpdump.git.
Then made a configure and make.

Is this git repository different from the one you are sharing ?

Regards,
Ajith
--------------------------------------------
codingfreak.in <http://www.codingfreak.in>

On Mon, May 28, 2012 at 12:01 PM, Artur Kielak <kielaka <at> vp.pl> wrote:

> > Thanks for the reply,
> >
> > I have generated Makefile from ./configure and doing a tcpdump build.
> >
> > Now if I build tcpdump it is linked with shared libraries of libpcap and
> > others as shown below. Is it possible for me to create tcpdump binary
> > linking up with all static libraries ?
> >
> > $ ldd tcpdump
> >     linux-gate.so.1 =>  (0x00816000)
> >     libcrypto.so.0.9.8 => /lib/i686/cmov/libcrypto.so.0.9.8 (0x00b95000)
> >     libpcap.so.0.8 => /usr/lib/libpcap.so.0.8 (0x002c9000)
> >     libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00110000)
> >     libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00340000)
(Continue reading)

Michael Richardson | 28 May 2012 16:20
Picon
Gravatar

Re: Building tcpdump with static libraries


>>>>> "Ajith" == Ajith Adapa <adapa.ajith <at> gmail.com> writes:
    Ajith> Actually I cloned the from git repository - git://github.com/mcr/tcpdump.git.
    Ajith> Then made a configure and make.

    Ajith> Is this git repository different from the one you are sharing ?

This git repo is pushed from the master at bpf.tcpdump.org every night.

--

-- 
]       He who is tired of Weird Al is tired of life!           |  firewalls  [
]   Michael Richardson, Sandelman Software Works, Ottawa, ON    |net architect[
] mcr <at> sandelman.ottawa.on.ca http://www.sandelman.ottawa.on.ca/ |device driver[
   Kyoto Plus: watch the video <http://www.youtube.com/watch?v=kzx1ycLXQSE>
	               then sign the petition. 
Guy Harris | 28 May 2012 10:26
Picon
Favicon

Re: Building tcpdump with static libraries


On May 27, 2012, at 11:31 PM, Artur Kielak wrote:

> I think than You run older version tcpdump:

You can't use ldd to find out the version of tcpdump; you have to run "tcpdump -h" to get the version of tcpdump.

> This is the answer:
> libpcap.so.0.8 => /usr/lib/libpcap.so.0.8 (0x002c9000)
> Linked to old version.

Just because the shared library file happens to end with ".0.8", that doesn't mean that it's version 0.8, or
version 0.8.x for any value of x, of libpcap.  I don't know what distribution Ajith is using, but, for
example, Debian still calls the shared library "libpcap.so.0.8" even though it's based, presumably, on
libpcap 1.1.1 in stable:

	http://packages.debian.org/stable/libs/libpcap0.8

and libpcap 1.2.1 in testing:

	http://packages.debian.org/testing/libs/libpcap0.8

and unstable:

	http://packages.debian.org/unstable/libs/libpcap0.8

and Ubuntu, being Debian-based, does the same.  Presumably the version number didn't change because the
binary interface to the library hasn't changed in a backwards-incompatible fashion for ages (new
routines and other new capabilities have been added, so the binary of an app built with a *later* shared
version of the library won't work with an *earlier* shared version of the library if they use those new
(Continue reading)

Ajith Adapa | 28 May 2012 11:28
Picon

Re: Building tcpdump with static libraries

Hi,

I am currently building tcpdump on Ubuntu 10.04 - 03 edition.

$ ./tcpdump -h
tcpdump version 4.4.0-PRE_GIT_2012_05_28
libpcap version 1.0.0
Usage: tcpdump [-aAbdDefhHIKlLnNOpqRStuUvxX] [ -B size ] [ -c count ]
        [ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]
        [ -i interface ] [ -M secret ]
        [ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]
        [ -W filecount ] [ -y datalinktype ] [ -z command ]
        [ -Z user ] [ expression ]

I even tried adding -static flag but I have got errors regarding dlopen and
dlclose. Not sure of exact error but will try again the same.

Regards,
Ajith
--------------------------------------------
codingfreak.in <http://www.codingfreak.in>

On Mon, May 28, 2012 at 1:56 PM, Guy Harris <guy <at> alum.mit.edu> wrote:

>
> On May 27, 2012, at 11:31 PM, Artur Kielak wrote:
>
> > I think than You run older version tcpdump:
>
> You can't use ldd to find out the version of tcpdump; you have to run
(Continue reading)

Guy Harris | 28 May 2012 20:47
Picon
Favicon

Re: Building tcpdump with static libraries


On May 28, 2012, at 2:28 AM, Ajith Adapa wrote:

> I am currently building tcpdump on Ubuntu

Given the "libpcap.so.0.8", I suspected you were either using Debian or a Debian derivative such as Ubuntu.

> $ ./tcpdump -h
> tcpdump version 4.4.0-PRE_GIT_2012_05_28

OK, that's a *VERY* recent version (as indicated by the the "On May 28, 2012, at 2:28 AM" above and the
"2012_05_28" in the version string) of tcpdump - and it's from the Git trunk (or whatever it's called in
Git), given the "4.4.0-PRE_GIT_" in the version string.

> libpcap version 1.0.0

OK, that's presumably the shared library that came with the system.

> I even tried adding -static flag but I have got errors regarding dlopen and
> dlclose.

Many UN*Xes make it difficult to link a program 100% statically.  (Some make it *impossible*, by not
supplying a static version of the "system library" - the one usually called "libc", but called
"libSystem" on the UN*X with the largest desktop market share, that being one of the UN*Xes that does not
supply a static version of that library.)

One way in which it can be difficult to link a program 100% statically is that:

	many UN*Xes have a plug-in architecture for routines such as getpwuid() and getpwnam(), so that support
for looking up user login names and user IDs can be configured to look in a local database, look up over the
(Continue reading)

Romain Francoise | 28 May 2012 14:13
Picon
Favicon
Gravatar

Re: Building tcpdump with static libraries

Guy Harris <guy <at> alum.mit.edu> writes:

> Presumably the version number didn't change because the binary interface
> to the library hasn't changed in a backwards-incompatible fashion for
> ages (new routines and other new capabilities have been added, so the
> binary of an app built with a *later* shared version of the library
> won't work with an *earlier* shared version of the library if they use
> those new routines or capabilities, but, modulo library bugs, the binary
> of an app built with an *earlier* shared version of the library should
> work with a *later* shared version of the library).

Yes, that's right.

--

-- 
Romain Francoise <rfrancoise <at> debian.org>
http://people.debian.org/~rfrancoise/

Michael Richardson | 28 May 2012 16:20
Picon
Gravatar

Re: Building tcpdump with static libraries


>>>>> "Guy" == Guy Harris <guy <at> alum.mit.edu> writes:
    Guy>and Ubuntu, being Debian-based, does the same.  Presumably the
    Guy>version number didn't change because the binary interface to the
    Guy>library hasn't changed in a backwards-incompatible fashion for
    Guy>ages (new routines and other new capabilities have been added,
    Guy>so the binary of an app built with a *later* shared version of
    Guy>the library won't work with an *earlier* shared version of the
    Guy>library if they use those new routines or capabilities, but,
    Guy>modulo library bugs, the binary of an app built with an
    Guy>*earlier* shared version of the library should work with a
    Guy>*later* shared version of the library).- 

Correct, they do not update the package name because the ABI hasn't
changed in an incompatible way.

--

-- 
]       He who is tired of Weird Al is tired of life!           |  firewalls  [
]   Michael Richardson, Sandelman Software Works, Ottawa, ON    |net architect[
] mcr <at> sandelman.ottawa.on.ca http://www.sandelman.ottawa.on.ca/ |device driver[
   Kyoto Plus: watch the video <http://www.youtube.com/watch?v=kzx1ycLXQSE>
	               then sign the petition. 

Artur Kielak | 28 May 2012 10:17
Picon
Favicon

Re: Building tcpdump with static libraries

> Hi,
> 
> Thanks for the reply - Artur Kielak
> 
> Actually I cloned the from git repository - git://github.com/mcr/tcpdump.git.
> Then made a configure and make.
> 
> Is this git repository different from the one you are sharing ?
> 
> Regards,
> Ajith
> --------------------------------------------
> codingfreak.in <http://www.codingfreak.in>
> 
> 
> On Mon, May 28, 2012 at 12:01 PM, Artur Kielak <kielaka <at> vp.pl> wrote:
> 
> > > Thanks for the reply,
> > >
> > > I have generated Makefile from ./configure and doing a tcpdump build.
> > >
> > > Now if I build tcpdump it is linked with shared libraries of libpcap and
> > > others as shown below. Is it possible for me to create tcpdump binary
> > > linking up with all static libraries ?
> > >
> > > $ ldd tcpdump
> > >     linux-gate.so.1 =>  (0x00816000)
> > >     libcrypto.so.0.9.8 => /lib/i686/cmov/libcrypto.so.0.9.8 (0x00b95000)
> > >     libpcap.so.0.8 => /usr/lib/libpcap.so.0.8 (0x002c9000)
> > >     libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00110000)
(Continue reading)

Ajith Adapa | 28 May 2012 17:01
Picon

Re: Building tcpdump with static libraries

Look for site http://www.tcpdump.org/.
> > git clone git://bpf.tcpdump.org/libpcap
> > git clone git://bpf.tcpdump.org/tcpdump
These are Current Development Version.

> > Cheers Artur Kielak

I am trying on NIGHTLY BUILD :)

I even tried using -static flag in Makefile

I getting following error. Seems directly using static flag wont solve

/Ajith/LABS/submission/tcpdump/./addrtoname.c:728: warning: Using
'getservent' in statically linked applications requires at runtime the
shared libraries from the glibc version used for linking
/home/codingfreak/Ajith/LABS/submission/tcpdump/./addrtoname.c:748:
warning: Using 'endservent' in statically linked applications requires at
runtime the shared libraries from the glibc version used for linking
print-sunrpc.o: In function `progstr':
/home/codingfreak/Ajith/LABS/submission/tcpdump/./print-sunrpc.c:163:
warning: Using 'getrpcbynumber' in statically linked applications requires
at runtime the shared libraries from the glibc version used for linking
/usr/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
(.text+0x336): undefined reference to `dlsym'
/usr/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
(.text+0x418): undefined reference to `dlerror'
/usr/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
(.text+0x4a6): undefined reference to `dlsym'
/usr/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
(Continue reading)

Guy Harris | 28 May 2012 20:53
Picon
Favicon

Re: Building tcpdump with static libraries


On May 28, 2012, at 8:01 AM, Ajith Adapa wrote:

> I getting following error. Seems directly using static flag wont solve
> 
> /Ajith/LABS/submission/tcpdump/./addrtoname.c:728: warning: Using
> 'getservent' in statically linked applications requires at runtime the
> shared libraries from the glibc version used for linking
> /home/codingfreak/Ajith/LABS/submission/tcpdump/./addrtoname.c:748:
> warning: Using 'endservent' in statically linked applications requires at
> runtime the shared libraries from the glibc version used for linking
> print-sunrpc.o: In function `progstr':
> /home/codingfreak/Ajith/LABS/submission/tcpdump/./print-sunrpc.c:163:
> warning: Using 'getrpcbynumber' in statically linked applications requires
> at runtime the shared libraries from the glibc version used for linking

Yes - getservent(), endservent(), and getrpcbynumber() also, on most UN*Xes, use the Name Service Switch
mechanism I mentioned in my previous message, and...

> /usr/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
> (.text+0x336): undefined reference to `dlsym'
> /usr/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
> (.text+0x418): undefined reference to `dlerror'
> /usr/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
> (.text+0x4a6): undefined reference to `dlsym'
> /usr/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
> (.text+0x588): undefined reference to `dlerror'
> /usr/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
> (.text+0x5f7): undefined reference to `dlclose'
> /usr/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
(Continue reading)

Artur Kielak | 28 May 2012 14:04
Picon
Favicon

Re: Building tcpdump with static libraries

> 
> On May 27, 2012, at 11:31 PM, Artur Kielak wrote:
> 
> > I think than You run older version tcpdump:
> 
> You can't use ldd to find out the version of tcpdump; you have to run "tcpdump -h" to get the version of tcpdump.
> 
> > This is the answer:
> > libpcap.so.0.8 => /usr/lib/libpcap.so.0.8 (0x002c9000)
> > Linked to old version.
> 
> Just because the shared library file happens to end with ".0.8", that doesn't mean that it's version 0.8,
or version 0.8.x for any value of x, of libpcap.  I don't know what distribution Ajith is using, but, for
example, Debian still calls the shared library "libpcap.so.0.8" even though it's based, presumably, on
libpcap 1.1.1 in stable:
> 
> 	http://packages.debian.org/stable/libs/libpcap0.8
> 
> and libpcap 1.2.1 in testing:
> 
> 	http://packages.debian.org/testing/libs/libpcap0.8
> 
> and unstable:
> 
> 	http://packages.debian.org/unstable/libs/libpcap0.8
> 
> and Ubuntu, being Debian-based, does the same.  Presumably the version number didn't change because the
binary interface to the library hasn't changed in a backwards-incompatible fashion for ages (new
routines and other new capabilities have been added, so the binary of an app built with a *later* shared
version of the library won't work with an *earlier* shared version of the library if they use those new
(Continue reading)

David Laight | 29 May 2012 11:24

Re: Building tcpdump with static libraries


> Can I know how to build tcpdump with static libraries rather than with
> shared libraries ?

Why are you trying to do this.
As Guy says in his recent posts you can't (and shouldn't) try to link
statically to all the system libraries.

If you are trying to link with a specific version of libpcap,
the look into the RPATH, RUNPATH, SONAME and NEEDED elf sections
and the use of $ORIGIN.

	David


Gmane