If you want to build your lib in the first stage and use it in the later stage without all the libs and tools needed to compile it, you can use a multistage build as you say.
But, when you copy the builded lib, you need to install the shared library that was linked to it (here musl and unixodbc).
You can find them by running ldd:
/build/mariadb-connector-odbc-3.1.4 # ldd /usr/lib/libmaodbc.so
/lib/ld-musl-x86_64.so.1 (0x7fde6847b000)
libodbcinst.so.2 => /usr/lib/libodbcinst.so.2 (0x7fde683c5000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fde6847b000)
As musl should be already present, you only need to install back the unixodbc lib used for building the lib.
This is an example of Dockerfile for that:
FROM alpine AS build
# Add build dependencies
RUN apk add --no-cache alpine-sdk cmake unixodbc-dev mariadb-connector-c mariadb-connector-c-dev mariadb-static unixodbc
# Download the source code from github
ADD https://github.com/MariaDB/mariadb-connector-odbc/archive/3.1.4.tar.gz /build/mariadb-connector-odbc.tgz
# Build it
WORKDIR /build
RUN tar xzf mariadb-connector-odbc.tgz \
&& cd mariadb-connector-odbc-3.1.4 \
&& CFLAGS="$CFLAGS -I/usr/include/mysql" \
cmake \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_LIBDIR=lib \
-DBUILD_SHARED_LIBS=True \
-DCMAKE_BUILD_TYPE=None \
. \
&& make install
# Final stage
FROM alpine
# Add the dependencies for the lib
RUN apk add --no-cache unixodbc
# Copy it from the build image
COPY --from=build /usr/lib/libmaodbc.so /usr/lib/libmaodbc.so