It's an '-Wl,--as-needed' problem. autoconf check calls 'krb5-config gssapi'. 'krb5-config gssapi krb5' would have worked. The result is: /usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/../../../../x86_64-pc-linux-gnu/bin/ld: ./.libs/libauth.a(mech-gssapi.o): undefined reference to symbol 'krb5_free_context@@HEIMDAL_KRB5_2.0'
Please attach the full build.log and the output of $(emerge --info).
Output of `krb5-config gssapi krb5 --libs` is `-Wl,--enable-new-dtags -Wl,-rpath -Wl,/usr/lib64 -L/usr/lib64 -lgssapi -lkrb5`. Output of `krb5-config gssapi --libs` is `-Wl,--enable-new-dtags -Wl,-rpath -Wl,/usr/lib64 -L/usr/lib64 -lgssapi`. With '-Wl,--as-needed' and krb5_free_context being used it's just obvious why it breaks in the second case and that's what the autoconf check uses. As for a workaround, I've simply sed-ed configure script with such change (both for '--libs' and '--cflags', even though '--cflags' in both cases returns '') - didn't feel like it's worth adding full autoreconf for something such trivial. Proper solution would be pinging the upstream to update that portion of configure.ac...well, actually in their repo on master they've restructured, so there it would be m4/want_gssapi.m4. This is likely triggered by the cleanup done in heimdal's krb5-config done around the time of changing versioning scheme.
should be fixed with https://github.com/dovecot/core/commit/2d316e272fc2c97fc729ee221189271799884c78 Please reopen if this is still a problem.