Statically Compiling Smartctl

16 Mar 2017

For CentOS/Fedora:

sudo yum install -y gcc gcc-g++ glibc-static libstdc++-static svn automake
svn co .
cd smartmontools
./configure LDFLAGS="-static"

Currently Smartctl 6.5 is the latest stable version. If there is a newer version out, then change the SVN tag to that version.

After the compilation finishes, check that the result is a static executable:

ldd smartctl

If everything when well, then you should get:

not a dynamic executable

glibc-static and libstdc++-static install static libraries (.a files) for the standard c and standard c++ libraries respectively. When you link against these static libraries using the -static flag, then the static library will be included in the executable itself and not be dynamically linked, allowing for portability on Linux distributions without worrying about the glibc ABI for older distributions.

The glibc Application Binary Interface is backward-compatible but not forward-compatible from the standpoint of the library. That means if you link your executable against a newer version of the glibc library, then that executable may refer to symbols that do not exist in the older version of the library.