This document describes how to build FRR without hard dependencies on shared
libraries. Note that it’s not possible to build FRR completely statically.
This document just covers how to statically link the dependencies that aren’t
likely to be present on a given platform - libfrr and libyang. The resultant
binaries should still be fairly portable. For example, here is the DSO
dependency list for bgpd after using these steps:
Note that these steps have only been tested with LLVM 9 / clang.
Today, libfrr can already be statically linked by passing these configure
--enable-static --enable-static-bin --enable-shared
libyang is more complicated. You must build and install libyang as a static
library. To do this, follow the usual libyang build procedure as listed in the
FRR developer docs, but set the
ENABLE_STATIC option in your cmake
invocation. You also need to build with PIC enabled, which today is disabled
when building libyang statically.
The resultant cmake command is:
cmake -DENABLE_STATIC=ON -DENABLE_LYD_PRIV=ON \
This produces a bunch of
.a static archives that need to ultimately be linked
into FRR. However, not only is it 6 archives rather than the usual
you will now also need to link FRR with
package provides this, but it hasn’t been built with PIC enabled, so it’s not
usable for our purposes. So download
SourceForge, and build it
Hopefully you get a nice, usable, PIC
So now we have to link all these static libraries into FRR. Rather than modify
FRR to accommodate this, the best option is to create an archive with all of
libyang’s dependencies. Then to avoid making any changes to FRR build foo,
libyang.a and copy it over the usual static library location.
Ugly but it works. To do this, go into your libyang build directory, which
should have a bunch of
.a files. Copy
libpcre.a into this directory.
Write the following into a shell script and run it:
ar -M <<EOM
libyang_fat.a is your archive. Now copy this over your install
libyang.a, which on my machine is located at
locate libyang.a if not).
Now when you build FRR with the static options enabled as above, clang should
pick up the static libyang and link it, leaving you with FRR binaries that have
no hard DSO dependencies beyond common system libraries. To verify, run
over the resultant binaries.