Bug 428807

Summary: Duplicate symbol linker error under clang/macOS
Product: [Frameworks and Libraries] frameworks-kio Reporter: Dawid Wróbel <me>
Component: generalAssignee: KIO Bugs <kio-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: a.samirh78, faure, kdelibs-bugs, vkrause
Priority: NOR    
Version: 5.75.0   
Target Milestone: ---   
Platform: Compiled Sources   
OS: macOS   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: vcpkg build output

Description Dawid Wróbel 2020-11-07 21:49:50 UTC
Created attachment 133120 [details]
vcpkg build output

SUMMARY
I am having trouble getting kio to compile under macOS. I am working on vcpkg portfile for it and it fails with 'duplicate symbol' error. While I know it compiles fine under craft, AFIK it doesn't use most recent macOS version/SDK/Xcode. It may also be that vcpkg has toolchain configured to be less lenient towards common errors.

Specifically the error reported is:

duplicate symbol 'operator>>(QDBusArgument const&, QSslCertificate&)' in:
    src/kssld/CMakeFiles/kssld.dir/kssld.cpp.o
    lib/libKF5KIOCore.a(ksslcertificatemanager.cpp.o)
duplicate symbol 'operator<<(QDBusArgument&, QSslCertificate const&)' in:
    src/kssld/CMakeFiles/kssld.dir/kssld.cpp.o
    lib/libKF5KIOCore.a(ksslcertificatemanager.cpp.o)
duplicate symbol 'operator>>(QDBusArgument const&, KSslCertificateRule&)' in:
    src/kssld/CMakeFiles/kssld.dir/kssld.cpp.o
    lib/libKF5KIOCore.a(ksslcertificatemanager.cpp.o)
duplicate symbol 'operator<<(QDBusArgument&, KSslCertificateRule const&)' in:
    src/kssld/CMakeFiles/kssld.dir/kssld.cpp.o
    lib/libKF5KIOCore.a(ksslcertificatemanager.cpp.o)
duplicate symbol 'operator>>(QDBusArgument const&, QSslError::SslError&)' in:
    src/kssld/CMakeFiles/kssld.dir/kssld.cpp.o
    lib/libKF5KIOCore.a(ksslcertificatemanager.cpp.o)
duplicate symbol 'operator<<(QDBusArgument&, QSslError::SslError const&)' in:
    src/kssld/CMakeFiles/kssld.dir/kssld.cpp.o
    lib/libKF5KIOCore.a(ksslcertificatemanager.cpp.o)
ld: 6 duplicate symbols for architecture x86_64

I did some investigation and here's what follows:
- the operators above are declared *and defined* in kssld_dbusmetatypes.h
- the header is in turn included by kssld_interface.h and kssld_adaptor.h, which are respectively included by the ksslcertificatemanager.cpp and kissed.cpp, which the linker is complaining about.

My rusty C++ tells me that the linker complains because the body of the operators is implemented in the kssld_dbusmetatypes header file. Despite my rather limited knowledge of Qt and its metatype macros, I tried to separate the implementation from the header, but failed miserably. 

Note that 5.73 had an identical issue.

STEPS TO REPRODUCE
1. You can try to build the vcpkg package using https://github.com/microsoft/vcpkg/pull/13469


SOFTWARE/OS VERSIONS
macOS: 10.15.7 (19H2)
KDE Frameworks Version: 5.75
Qt Version: 5.15
Apple clang version 11.0.3 (clang-1103.0.32.62)
Comment 1 Ahmad Samir 2020-11-10 18:41:39 UTC
Might be related to the friend declarations in src/core/ksslcertificatemanager.h .. not sure though.
Comment 2 Dawid Wróbel 2020-11-10 19:54:34 UTC
I thought so, too, but I commented all that code and the references to befriended private members elsewhere, but still seeing the same issue.
Comment 3 Volker Krause 2020-11-11 10:07:13 UTC
Does adding `inline` to those operators help?
Comment 4 Dawid Wróbel 2020-11-11 15:08:24 UTC
It obviously does, I don't know why I didn't think about it!
Comment 5 Ahmad Samir 2020-12-02 12:39:33 UTC
@Volker, has this been fixed? (does it need fixing?)
Comment 6 Volker Krause 2020-12-02 16:18:32 UTC
I didn't submit this change (I was just guessing, I don't even have it locally), but it sounds like we should add it indeed.
Comment 7 Bug Janitor Service 2021-08-30 20:27:28 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/563
Comment 8 Dawid Wróbel 2021-08-31 17:27:51 UTC
Git commit eaa2729e17a15261f41599ad8c47124b486e4319 by Dawid Wróbel.
Committed on 30/08/2021 at 20:23.
Pushed by wrobelda into branch 'master'.

Inline kssld operators to avoid duplicate symbol errors

M  +6    -6    src/core/kssld_dbusmetatypes.h

https://invent.kde.org/frameworks/kio/commit/eaa2729e17a15261f41599ad8c47124b486e4319