-ObjC flag causes duplicate symbols with Swift Packages

I'm working with a product that has the following dependency graph:

App (with -ObjC flag) -> Static lib

I'm beginning work on a new module and I'd love for it to be a Swift Package. So, I go ahead and create a new swift package and add it as a dependency to the Static lib using the Xcode 11b5 Swift Package. When I attempt to build, I immediately get a linker error:

x duplicate symbols for architecture x86_64

When I test this with a brand new project following the same structure but without the application's -ObjC linker flag, everything builds fine. However, the project I'm working on requires that flag to build.

What am I missing here?

Cheers,
Stephen

I think we'll need more information on which symbols are duplicated and what the contents of the various pieces here are. I wasn't able to reproduce this by replicating your set up in a simple example.

1 Like

Thanks for looking into this! I've pushed a repo of the project that I'm able to repro this in here: https://github.com/ciauri/Halp

Just init the Package dir as a git repo, make a dummy commit, then add it as a swift package dependency to the StaticLib project via the xcode tool and then attempt to build the App target. The static lib target will build fine, it's just the App that seems to have this issue.

Here is the resulting error message:

Showing Recent Messages
Ld /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/App.app/App normal x86_64 (in target 'App' from project 'App')
    cd /Users/stephen.ciauri/Downloads/Halp-master/App
    /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-ios13.0-simulator -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.0.sdk -L/Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator -F/Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator -filelist /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Intermediates.noindex/App.build/Debug-iphonesimulator/App.build/Objects-normal/x86_64/App.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Intermediates.noindex/App.build/Debug-iphonesimulator/App.build/Objects-normal/x86_64/App_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Intermediates.noindex/App.build/Debug-iphonesimulator/App.build/Objects-normal/x86_64/App.swiftmodule -ObjC -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Intermediates.noindex/App.build/Debug-iphonesimulator/App.build/App.app-Simulated.xcent /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a -Xlinker -dependency_info -Xlinker /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Intermediates.noindex/App.build/Debug-iphonesimulator/App.build/Objects-normal/x86_64/App_dependency_info.dat -o /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/App.app/App -Xlinker -add_ast_path -Xlinker /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Intermediates.noindex/StaticLib.build/Debug-iphonesimulator/StaticLib.build/Objects-normal/x86_64/StaticLib.swiftmodule

duplicate symbol 'Package.Package.init(text: Swift.String) -> Package.Package' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
duplicate symbol 'default argument 0 of Package.Package.init(text: Swift.String) -> Package.Package' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
duplicate symbol 'Package.Package.text.modify : Swift.String' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
duplicate symbol 'Package.Package.text.getter : Swift.String' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
duplicate symbol 'property descriptor for Package.Package.text : Swift.String' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
duplicate symbol 'variable initialization expression of Package.Package.text : Swift.String' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
duplicate symbol 'Package.Package.text.setter : Swift.String' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
duplicate symbol 'Package.Package.init() -> Package.Package' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
duplicate symbol 'type metadata accessor for Package.Package' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
duplicate symbol 'nominal type descriptor for Package.Package' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
duplicate symbol 'type metadata for Package.Package' in:
    /Users/stephen.ciauri/Library/Developer/Xcode/DerivedData/App-czvrzrbbjmoyjdcjoekskyustvxd/Build/Products/Debug-iphonesimulator/libStaticLib.a(Package.o)
ld: 11 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Thanks, I was able to reproduce this issue. This issue isn't related to OSS SwiftPM, would you mind filing a bug report at https://feedbackassistant.apple.com?

1 Like

Wonderful news!

Donezo: FB7040693

Thanks again for your help, Aciid.

Thank you!

Terms of Service

Privacy Policy

Cookie Policy