-
I've been trying for the past 3 days to build a DuckDB Static Library to use with this library, but nothing has worked so far. My latest approach is to build DuckDB mostly similar to https://github.com/duckdb/duckdb/blob/v1.2.2/.github/workflows/BundleStaticLibs.yml . The build script I'm using (after many other attempts) looks like this: #!/bin/bash
export PWD=`pwd`
docker run \
-v$PWD:$PWD \
-e CMAKE_BUILD_PARALLEL_LEVEL=2 \
-e EXTENSION_CONFIGS="$PWD/extension_config.cmake" \
-e ENABLE_EXTENSION_AUTOLOADING=1 \
-e ENABLE_EXTENSION_AUTOINSTALL=1 \
-e BUILD_BENCHMARK=1 \
-e FORCE_WARN_UNUSED=1 \
-e VCPKG_TARGET_TRIPLET=arm64-linux \
-e VCPKG_ROOT=$PWD/duckdb/vcpkg \
-e VCPKG_TOOLCHAIN_PATH=$PWD/duckdb/vcpkg/scripts/buildsystems/vcpkg.cmake \
-e USE_MERGED_VCPKG_MANIFEST=1 \
-e STATIC_OPENSSL=1 \
-e STATIC_LIBCPP=1 \
-e EXTENSION_STATIC_BUILD=1 \
quay.io/pypa/manylinux_2_28_aarch64 \
bash -c "yum install -y perl-IPC-Cmd curl zip unzip tar gcc gcc-c++ ninja-build && (cd $PWD/duckdb && bash $PWD/install_vcpkg.sh) && git config --global --add safe.directory $PWD/duckdb && make bundle-library -C $PWD/duckdb"
#!/bin/bash
set -eux
rm -rf vcpkg
mkdir vcpkg
cd vcpkg
git init
git remote add origin "https://github.com/microsoft/vcpkg.git"
git fetch origin "ce613c41372b23b1f51333815feb3edd87ef8a8b"
git checkout "ce613c41372b23b1f51333815feb3edd87ef8a8b"
./bootstrap-vcpkg.sh Where duckdb_extension_load(core_functions)
duckdb_extension_load(parquet)
duckdb_extension_load(json)
duckdb_extension_load(icu)
duckdb_extension_load(httpfs
GIT_URL https://github.com/duckdb/duckdb-httpfs
GIT_TAG c22532453e9fab8404f91729708d9f35e23d323d
INCLUDE_DIR extension/httpfs/include
)
duckdb_extension_load(aws
GIT_URL https://github.com/duckdb/duckdb-aws
GIT_TAG e92e45b30ba17594b1101db22699a2244adfaeb1
) The build seems to work and results in a When I'm trying to build my go-app using the following Dockerfile: FROM --platform=linux/arm64 golang:1.24
RUN mkdir /build
WORKDIR /build
ENV GOOS=linux
ENV GOARCH=arm64
ENV CGO_ENABLED=1
ENV CPPFLAGS="-DDUCKDB_STATIC_BUILD"
ENV CGO_LDFLAGS="-lduckdb_bundle -lstdc++ -lm -ldl -L/build/cron/libs"
COPY ../.. .
WORKDIR /build/cron
RUN go build -o bootstrap -tags "lambda,lambda.norpc,duckdb_use_static_lib" ( The build of the go app fails with a lot of errors:
I'm at a point where I'm completely lost what else I should try, also because I'm not at all familiar with the C/C++ Ecosystem und buildsystems |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 2 replies
-
Hi @its-felix, I can try to give you some pointers to hopefully fix this, based on what I can tell from your description.
After Once you've confirmed that, the next step is indeed to build you Go app. Then, change your docker file like so
I am suggesting these steps because the linker error suggests that somehow the AWS library is missing (i.e., it is not part of the bundled library). And figuring out why that is the case should (might) hopefully resolve this for you. 🤞 |
Beta Was this translation helpful? Give feedback.
-
Thanks for the pointers, this helped me a bit figuring out what exactly happens. I think I got a little further now by also pulling Currently, I'm using the following Dockerfile to build the archive: FROM golang:1.24 AS build
WORKDIR /build
RUN mkdir libs
COPY duckdb/build/release/libs/*.a ./libs
COPY duckdb/build/release/vcpkg_installed/arm64-linux/lib/*.a ./libs
WORKDIR /build/libs
RUN echo *.a | xargs -n1 ar x
RUN echo *.o | xargs ar rcs ../libduckdb_bundle.a
FROM scratch
COPY --from=build /build/libduckdb_bundle.a .
COPY --from=build /build/libs/* ./libs/ The For reference, this is (part of) my current go build output:
Most of the missing things should apparently be part of |
Beta Was this translation helpful? Give feedback.
-
I was able to confirm that my
but the unpacked
I assume some other archive contains a different |
Beta Was this translation helpful? Give feedback.
-
I was able to resolve above issue by unpacking each archive into its own subdirectory: FROM quay.io/pypa/manylinux_2_28_aarch64 AS build
WORKDIR /build
RUN mkdir libs
COPY duckdb/build/release/libs/*.a ./libs
COPY duckdb/build/release/vcpkg_installed/arm64-linux/lib/*.a ./libs
WORKDIR /build/libs
RUN ls *.a | xargs -n1 -I{} sh -c 'mkdir -p "objs-{}" && (cd "objs-{}" && ar x "../{}")'
RUN echo objs-*/*.o | xargs ar rcs ../libduckdb_bundle.a
FROM scratch
COPY --from=build /build/ ./ It turns out that jemalloc contains a
And the unpacked AWS version of
Some other symbols are missing now:
However, this time I can find the symbol in the final bundle already:
|
Beta Was this translation helpful? Give feedback.
-
(Documenting all this in hope anyone with the same error messages might find this helpful in the future) After coming across some more missing symbols, I figured out that even within the same archive there are duplicate names, i.e. in I adjusted the build a bit accordingly:
#!/bin/sh
set -eux
mkdir -p "objs-$1"
cd "objs-$1"
i=0
ar t "../$1" | while read member
do
(mkdir -p "$i" && cd "$i" && ar x "../../$1" "$member")
i=$((i+1))
done Now down to some more undefined symbols:
|
Beta Was this translation helpful? Give feedback.
-
After expanding my #!/bin/sh
set -eux
mkdir -p "objs-$1"
cd "objs-$1"
ftemp=$(mktemp)
cp "../$1" "$ftemp"
i=0
while true
do
member=$(ar t "$ftemp" | head -n 1)
if [ -z "$member" ]; then
break
fi
(mkdir -p "$i" && cd "$i" && ar x "$ftemp" "$member")
ar d "$ftemp" "$member"
i=$((i+1))
done
rm "$ftemp" During go build:
|
Beta Was this translation helpful? Give feedback.
-
One more thing, maybe instead of touching and (re)bundling the archives (libs), you could try to leave them as they are, and just provide all of them in the linking command (it'll look ugly, but maybe you can avoid duplicate symbol issues)? See the Another pit that I fell into before is that on Linux (not sure what system you are on) linking order matters.
|
Beta Was this translation helpful? Give feedback.
-
Thanks for all your help @taniabogatsch ! I turns out that the issue was simply a incompatability between After switching the base image for my Go-Build to For future readers, my working Dockerfile for the GO BUILD looks like this: FROM quay.io/pypa/manylinux_2_28_aarch64 AS build
ADD "https://go.dev/dl/go1.24.2.linux-arm64.tar.gz" ./go.tar.gz
RUN tar -C /usr/local -xzf go.tar.gz && rm go.tar.gz
ENV PATH="$PATH:/usr/local/go/bin"
ENV GOOS=linux
ENV GOARCH=arm64
ENV CGO_ENABLED=1
ENV CPPFLAGS="-DDUCKDB_STATIC_BUILD"
# ENV CGO_LDFLAGS="-lduckdb_static -lcore_functions_extension -licu_extension -ljson_extension -lparquet_extension -ljemalloc_extension -lhttpfs_extension -laws_extension -laws-cpp-sdk-core -lcurl -lcrypto -lssl -lz -laws-crt-cpp -laws-c-common -laws-c-io -ls2n -laws-c-cal -laws-c-http -laws-c-compression -lduckdb_fastpforlib -lduckdb_fmt -lduckdb_fsst -lduckdb_hyperloglog -lduckdb_mbedtls -lduckdb_miniz -lduckdb_pg_query -lduckdb_re2 -lduckdb_skiplistlib -lduckdb_utf8proc -lduckdb_yyjson -lduckdb_zstd -lstdc++ -lm -ldl -L/build/database/libs"
ENV CGO_LDFLAGS="-lduckdb_bundle -lstdc++ -lm -ldl -L/build/database/libs"
WORKDIR /build
COPY ../.. .
WORKDIR /build/database
RUN go build -o database -tags "lambda,duckdb_use_static_lib"
FROM gcr.io/distroless/cc:nonroot
COPY --from=build --chown=nonroot:nonroot /build/database/database /usr/local/bin/database
USER nonroot
ENTRYPOINT ["/usr/local/bin/database"] And the "fat-build" of Should the DuckDB Also, another question out of curiosity ... How/Why does a regular |
Beta Was this translation helpful? Give feedback.
-
As far as I know, we're building our libraries with that manylinux image ( |
Beta Was this translation helpful? Give feedback.
-
This is what we do since the v1.2.2 release of DuckDB |
Beta Was this translation helpful? Give feedback.
Thanks for all your help @taniabogatsch !
I turns out that the issue was simply a incompatability between
gcc
/g++
used in the DuckDB Build, where I usedquay.io/pypa/manylinux_2_28_aarch64
and the one present ingolang:1.24
.After switching the base image for my Go-Build to
quay.io/pypa/manylinux_2_28_aarch64
the build succeeds with the fat-bundled DuckDB as described above (unpack and repack everything fromduckdb/build/release/libs
andduckdb/build/release/vcpkg_installed/arm64-linux/lib
).For future readers, my working Dockerfile for the GO BUILD looks like this: