16

I've download gdb-6.5.bz2.tar. Untar this file. I write: LDFLAGS=-static ./configure

but as a result i get a gdb, which require a so files, for instance: ncurses.so.5 libc.so.0 etc

How i can build statically ?

4
  • 2
    You probably can't. If you want to, you'll have to get static versions of all the prerequisite libraries, which is probably more recompilation than is worth your while. Why do you want to build a statically linked GDB? The dynamically linked version will be much simpler. Commented Feb 20, 2012 at 16:42
  • 6
    @JonathanLeffler: If you want to debug a newly-bootstrapped system, static-linked gdb is extremely valuable. This is even more true if the new system will be using an incompatible ABI from the original system you're building on -- for example, a different libc or a different default calling convention. Commented Oct 2, 2012 at 5:03
  • @R..: fine, but then you'll need to obtain or build a static library for each and every library that GDB links with. On a RHEL 5 system, that means: libreadline.so.5, libncurses.so.5, libm.so.6, libexpat.so.0, libdl.so.2, libc.so.6, /lib64/ld-linux-x86-64.so.2 if the output of ldd /usr/bin/gdb is to be trusted. I'm not sure whether you'd really want to replace all those with static libraries, but that's the list of shared libraries used by gdb on this (antique) platform. Commented Oct 2, 2012 at 6:00
  • 1
    That's just glibc, readline, ncurses, and expat - 4 libraries. libdl, libc, ld-linux, and libm are all part of glibc. Commented Oct 2, 2012 at 13:49

4 Answers 4

10

This message seems to imply that the correct usage is

$ make LDFLAGS=-static

Which seems surprising. Unfortunately, it also says it fails to build, and there are no follow-ups. Still the message is from 1999 so everything might have changed, perhaps the proper way today is to do it your way.

Sign up to request clarification or add additional context in comments.

1 Comment

What version of gdb were you able to build this way @Changbin Du, and what distro/version did you compile from?
10

Both gcc and gdb disrespect the --enable-static flag which should be passed to configure, the correct way to do this is:

In the case of gdb 8.0, you have to also add the --disable-interprocess-agent to successfully build a static version:

mkdir build-gdb && cd build-gdb && ../configure --prefix=... --enable-static --disable-interprocess-agent ...

In the case of gcc 7.1, you have to also add the --disable-libcc1 to successfully build a static version:

mkdir build-gcc && cd build-gcc && ../configure --prefix=... --enable-static --disable-shared --disable-libcc1 ...

2 Comments

I'm curious how you found these options. The documentations did not mention these.
I build with --enable-static=yes, but the output is still dynamically linked.
7

You can use the following options for configure script to generate a static GDB executable:

./configure --prefix=<> --enable-static=yes && make && make install

Comments

3

I recently went through the hassle of compiling gdb-15.x and gdb-server-15.x for multiple architectures.

Whoever wants to use this newer version can download it at gdb-static

The repository also contains a compilation.md file describing the necessary steps in order to compile gdb/gdbserver statically (as of now).

gdb 15 contains vast improvements over the latest static gdb i could find online (8.3.1).

EDIT: The repository has been updated to support gdb-16.x

1 Comment

While the README in your github project is clear enough on the steps - how to build static dependencies first, then how to change gdb's Makefile to build statically - SO answers ideally contain more than "links to external sources". Yes, I'm suggesting you write down the steps taken - here. Definitely reference your github project, but don't make the answer useless should that, for whatever reason, go away at a point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.