Domino on Linux/Unix, Troubleshooting, Best Practices, Tips and more ...

alt

Daniel Nashed

Building statically linked on Alpine to run glibc independent including OpenSSL and RapidJSON

Daniel Nashed – 28 April 2025 07:44:37

Building applications on Linux can be tricky. The standard C library "glibc" is upward compatible.
But binaries compiled on newer glibc do not work on older Linux versions.


One way around it, would be to build statically linked binaries, which includes all required glibc functionality the binary uses.

With OpenSSL it is the opposite way. Your favorite distribution might not have the latest OpenSSL version installed.


But dynamically linking has also advantages:


- Size of the binary

- You can patch libs on OS level and the application benefits from it


Choosing Alpine Linux as the build platform offers very up to date Libs.

In addition if you are building smaller applications you don't need all the fancy glibc functionality.
Alpine is based on the smaller musl C standard lib (
https://musl.libc.org/) which can be statically linked quite easy.

For a smaller application building on Alpine and statically linking all needed resource like OpenSSL, RapidJSON and other libs can make a lot of sense.


I have been looking into this today for an application that just needs RapidJSON and plain C++ code.

But once that worked, I looked into other projects which require OpenSSL in the next step.

You could create a build container or just get the compiler installed into a container if this is a one time compile only.

The following line creates a container, adds all software dependencies and builds a small, statically linked binary.



Example: Command-Line for Docker based build


docker run --rm -v $(pwd):/src -w /src alpine:latest sh -c "apk add --no-cache g++ make musl-dev rapidjson-dev curl-dev openssl-dev openssl-libs-static && cd /src && make -f makefile_alpine_static"



Example: makefile_alpine_static


CXX = g++

CXXFLAGS = -O2 -Wall -static -pedantic

LDFLAGS = -lssl -lcrypto

TARGET = nshmailx

SRC = nshmailx.cpp

OBJ = nshmailx.o


all: $(TARGET)


$(TARGET): $(OBJ)

      $(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJ) $(LDFLAGS)


$(OBJ): $(SRC)

      $(CXX) $(CXXFLAGS) -c $(SRC) -o $(OBJ)


clean:

      rm -f $(TARGET) $(OBJ)


Links

    Archives


    • [HCL Domino]
    • [Domino on Linux]
    • [Nash!Com]
    • [Daniel Nashed]