Linking error with G++ 15.2

Robert J. Hansen rjh at sixdemonbag.org
Sat Nov 15 05:04:38 CET 2025


/* This code should not be used as an example of good style.

    This code does nothing useful and may even import garbage
    into your keyring. It is to be compiled as an example of
    a linker failure, not actually executed.

    System: Apple M4 Macbook (aarch64) running Tahoe 26.1.

    First, using Apple Clang++ 17.0.0, everything compiles cleanly:

$ clang++ foo.cc \
`pkg-config --cflags --libs gpgmepp` -o foo -O2 -Wall --std=c++23

    … but GNU C++ 15.2.0 can't link:

$ g++-15 foo.cc \
`pkg-config --cflags --libs gpgmepp` -o foo -O2 -Wall --std=c++23

Undefined symbols for architecture arm64:
   "GpgME::Error::asStdString[abi:cxx11]() const", referenced from:
       _main in cc3RBL1t.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
*/

#include "gpgme++/context.h"
#include "gpgme++/data.h"
#include "gpgme++/importresult.h"
#include <memory>
#include <print>

const char* data = "this should not be imported";

int main()
{
     GpgME::initializeLibrary();
     const std::unique_ptr<GpgME::Context> ctx {
         GpgME::Context::createForProtocol(GpgME::OpenPGP)
     };
     auto buffer = GpgME::Data(data, strlen(data), true);
     auto errcode = ctx->importKeys(buffer);
     if (errcode.error().isError()) {
       std::println(stderr, "Couldn’t import key: {}",
         errcode.error().asStdString());
     }
     return 0;
}




More information about the Gnupg-devel mailing list