# \-ObjC flag causes duplicate symbols with Swift Packages

**URL:** <https://forums.swift.org/t/objc-flag-causes-duplicate-symbols-with-swift-packages/27926>\
**Category:** Package Manager\
**Tags:** packagemanager\
**Created:** [August 15, 2019, 6:06pm UTC](https://forums.swift.org/t/objc-flag-causes-duplicate-symbols-with-swift-packages/27926 "2019-08-15T18:06:15Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [November 2, 2019, 6:08pm UTC](https://forums.swift.org/t/objc-flag-causes-duplicate-symbols-with-swift-packages/27926/18 "2019-11-02T18:08:44Z")

</div>

> [@rsebbe](#):
>
> I don't think this is related to the -ObjC flag. Looking at the github sample project, the problem is that Xcode will link the Package static lib into the static lib target, and then it will do it again on the app, leading to duplicate symbols.

If you're referring to @ciauri's project above, there's no evidence of that in the build log. What's happening is:

1. The `Package` target (Swift package target) is built, producing a relocatable object file (instead of a static library) (`clang -r ... -o Package.o`).

2. The `StaticLib` target (Xcode static library target) is built, producing a static library. The file list passed to `libtool` contains the `.o` file from its own `.swift` source and the `Package.o` from the dependency. But, `Package.o` is also passed separately on the command line outside of the file list. `libtool` doesn't deduplicate these inputs, and even emits a warning about the conflict:

3. The App target (Xcode app target) is built. The linker takes the object files for the target's own `.swift` files as inputs in the file list, and then the command line also includes `libStaticLib.a`. It does **not** separately contain `Package.o` from step 1.

There's another way that we can verify that `-ObjC` is causing the problem here—just remove it from the App target. If we do that, the App links fine, because there are no references to symbols from `Package` in App. Even if we have App reference a symbol in Package, it _still_ works without `-ObjC` because the linker stops looking once it finds the first object file in `libStaticLib.a` that defines the symbols it's looking for. Since the two copies of `Package.o` are the same, it will never find symbols in the second one that it hasn't already found in the first one, so the duplicate never gets pulled in unless you force it.

---

_[View the full topic](https://forums.swift.org/t/objc-flag-causes-duplicate-symbols-with-swift-packages/27926)._
