mpgen: Change Cap'n Proto link order to fix undefined references in static builds #367

pull mutatrum wants to merge 1 commits into bitcoin-core:master from mutatrum:patch-1 changing 1 files +1 −1
  1. mutatrum commented at 1:16 PM on September 17, 2026: contributor

    When building against static Cap'n Proto libraries, mpgen compilation fails at link time as libcapnpc.a depends on symbols defined in libcapnp.a.

    Flipping the order fixes the undefined references.

    I ran into this issue when compiling Bitcoin Core with IPC enabled in a Ubuntu/Debian container to produce self-contained binaries that can be extracted to a host.

  2. Change CapnProto library linkage for mpgen
    When building against static Cap'n Proto libraries, `mpgen` compilation fails at link time as `libcapnpc.a` depends on symbols defined in `libcapnp.a`.
    
    Flipping the order fixes the undefined references.
    56cfdaa884
  3. DrahtBot commented at 1:16 PM on September 17, 2026: none

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK ryanofsky

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. mutatrum renamed this:
    Change Cap'n Proto library linkage order for mpgen
    mpgen: Change Cap'n Proto library linkage order to fix undefined references on static li
    on Sep 17, 2026
  5. mutatrum renamed this:
    mpgen: Change Cap'n Proto library linkage order to fix undefined references on static li
    mpgen: Change Cap'n Proto link order to fix undefined references in static builds
    on Sep 17, 2026
  6. hebasto commented at 1:20 PM on September 17, 2026: member

    When building against static Cap'n Proto libraries, mpgen compilation fails at link time as libcapnpc.a depends on symbols defined in libcapnp.a.

    Could you please provide the exact steps to reproduce the issue, including the toolchain details?

  7. mutatrum commented at 2:00 PM on September 17, 2026: contributor

    Use the following Dockerfile:

    FROM ubuntu:22.04
    
    ENV DEBIAN_FRONTEND=noninteractive
    RUN apt-get update -qq && apt-get install -y --no-install-recommends \
        build-essential cmake git curl ca-certificates pkg-config
    
    WORKDIR /tmp
    RUN curl -sSL https://capnproto.org/capnproto-c++-1.1.0.tar.gz | tar -xz && \
        cd capnproto-c++-1.1.0 && \
        ./configure --prefix=/usr --disable-shared --enable-static CXXFLAGS="-fPIC" CFLAGS="-fPIC" && \
        make -j$(nproc) && \
        make install
    
    WORKDIR /src
    RUN git clone https://github.com/bitcoin-core/libmultiprocess.git && \
        cd libmultiprocess && \
        cmake -B build && \
        cmake --build build --target mpgen
    

    Run docker build . results in:

    5.397 schema-parser.c++:(.text+0x117d): undefined reference to `capnp::SchemaLoader::get(unsigned long, capnp::schema::Brand::Reader, capnp::Schema) const'
    5.397 schema-parser.c++:(.text+0x1538): undefined reference to `capnp::SchemaLoader::get(unsigned long, capnp::schema::Brand::Reader, capnp::Schema) const'
    5.397 schema-parser.c++:(.text+0x1ba4): undefined reference to `capnp::SchemaLoader::get(unsigned long, capnp::schema::Brand::Reader, capnp::Schema) const'
    ...
    5.487 collect2: error: ld returned 1 exit status
    5.488 gmake[3]: *** [CMakeFiles/mpgen.dir/build.make:104: mpgen] Error 1
    5.488 gmake[2]: *** [CMakeFiles/Makefile2:969: CMakeFiles/mpgen.dir/all] Error 2
    5.488 gmake[1]: *** [CMakeFiles/Makefile2:976: CMakeFiles/mpgen.dir/rule] Error 2
    5.488 gmake: *** [Makefile:582: mpgen] Error 2
    
  8. in CMakeLists.txt:208 in 56cfdaa884
     203 | @@ -204,8 +204,8 @@ add_executable(mpgen src/mp/gen.cpp $<TARGET_OBJECTS:mputil>)
     204 |  add_executable(Libmultiprocess::mpgen ALIAS mpgen)
     205 |  target_include_directories(mpgen PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
     206 |  target_include_directories(mpgen PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
     207 | -target_link_libraries(mpgen PRIVATE CapnProto::capnp)
     208 |  target_link_libraries(mpgen PRIVATE CapnProto::capnpc)
     209 | +target_link_libraries(mpgen PRIVATE CapnProto::capnp)
    


    ryanofsky commented at 2:04 PM on October 1, 2026:

    In commit "Change CapnProto library linkage for mpgen" (56cfdaa884e710a2ddf6d9636141c36269a034c1)

    Note: This is a Cap'n Proto packaging bug, not a libmultiprocess one. In autotools installs, capnpc.pc has Requires: kj but leaves out capnp, so the CapnProto::capnpc target that CapnProtoTargets.cmake generates from it doesn't know it depends on capnp. With static libraries, capnp then has to come after capnpc on the link line, which is what this PR does.

    CMake installs of Cap'n Proto declare the dependency correctly, and with shared libraries the order doesn't matter, so CI never hit this. The other Cap'n Proto targets we link list their dependencies correctly, so this swap is a complete fix.

  9. ryanofsky approved
  10. ryanofsky commented at 2:29 PM on October 1, 2026: collaborator

    Code review ACK 56cfdaa884e710a2ddf6d9636141c36269a034c1. Thanks for the fix and the clear reproduction steps! The cause is a bug in Cap'n Proto's autotools packaging (details in the inline comment).

    I'm planning to merge this as-is, but two follow-ups could be worth doing:

    • Upstream fix: capnpc.pc.in has been missing Requires: capnp since it was added in capnproto/capnproto#1047 in 2020, and it is still missing in v1.5.0. Fixing it would help other projects using CapnProto::capnpc. We would still need the order here for older versions.
    • CI coverage: this fix depends on line order that nothing tests, so a later cleanup could undo it. ci/scripts/ci.sh already builds Cap'n Proto from source when a config sets CAPNP_CHECKOUT, but always with CMake. A CAPNP_BUILD=autotools-static setting next to it could make that step build with autotools instead (autoreconf -i, ./configure --disable-shared --enable-static, make install), so newdeps or a new config could turn it on with one line.
  11. ryanofsky merged this on Oct 1, 2026
  12. ryanofsky closed this on Oct 1, 2026

  13. mutatrum deleted the branch on Oct 1, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/libmultiprocess. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-10-08 00:30 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me