Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined symbols when used as dependency of multiple targets (Swift Packages in Xcode) #408

Open
cjwirth opened this issue May 6, 2024 · 4 comments · May be fixed by #470
Open

Undefined symbols when used as dependency of multiple targets (Swift Packages in Xcode) #408

cjwirth opened this issue May 6, 2024 · 4 comments · May be fixed by #470
Labels
bug Something isn't working triage Issues that need to be triaged

Comments

@cjwirth
Copy link

cjwirth commented May 6, 2024

Describe the bug
When building the app, I get undefined symbol errors, saying that it can't find symbols that exist in AppAuthCore:

ld: Undefined symbols:
  _OBJC_CLASS_$_OIDAuthState, referenced from:
       in GoogleSignIn.o
  _OBJC_CLASS_$_OIDAuthorizationRequest, referenced from:
       in GoogleSignIn.o
  _OBJC_CLASS_$_OIDAuthorizationService, referenced from:
       in GoogleSignIn.o
  _OBJC_CLASS_$_OIDIDToken, referenced from:
       in GoogleSignIn.o
  _OBJC_CLASS_$_OIDServiceConfiguration, referenced from:
       in GoogleSignIn.o
  _OBJC_CLASS_$_OIDURLQueryComponent, referenced from:
       in GoogleSignIn.o
  _OIDOAuthErrorResponseErrorKey, referenced from:
      +[GIDEMMSupport handleTokenFetchEMMError:completion:] in GoogleSignIn.o
  _OIDOAuthTokenErrorDomain, referenced from:
      ___53-[GIDGoogleUser refreshTokensIfNeededWithCompletion:]_block_invoke.22 in GoogleSignIn.o
  _OIDResponseTypeCode, referenced from:
      -[GIDSignIn authenticateInteractivelyWithOptions:] in GoogleSignIn.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This only happens if GoogleSignIn is added as a dependency of multiple targets that end up in the resulting app. If GoogleSignIn is only included into one target, it seems to be OK. But when it's included in multiple targets, I get the error above.

I have created a reproducible sample using the ObjC sample app provided by this repo.

To Reproduce
Steps to reproduce the behavior:

  1. Open the sample app in Xcode
  2. Create another Framework target that the main app depends on
  3. Make the new Framework target depend on GoogleSignIn
  4. Build the app -- see the errors

Or checkout the reproducible sample that I put together and try building it.

The app is basically structured like this in terms of project and dependencies:

.
└── AppTarget
    ├── GoogleSignIn
    ├── OnboardingFramework
    │   └── GoogleSignIn
    └── LoginFramework
        └── GoogleSignIn

Expected behavior
The app should build.

Screenshots
[available on request, but really nothing worth sharing, I don't think?]

Environment

  • GoogleSignIn-iOS Versions: 7.1.0, 6.2.4
  • Xcode: Have tried on Xcode 15.2, 15.3, and 15.4
  • OS: macOS 14.4.1, 14.5
@cjwirth cjwirth added bug Something isn't working triage Issues that need to be triaged labels May 6, 2024
@cjwirth cjwirth changed the title Undefined symbols when used as transitive dependency (Swift Packages in Xcode) Undefined symbols when used as dependency of multiple targets (Swift Packages in Xcode) May 13, 2024
@okuchmii
Copy link

okuchmii commented Jun 4, 2024

@cjwirth do you have any solution for this scenario as a workaround?

@cjwirth
Copy link
Author

cjwirth commented Jun 4, 2024

Unfortunately the only thing that has worked for me is to keep it in CocoaPods and not use the Package.

The only things I have issues with and need to use CocoaPods for are related to Google lol. Everything else has been fine.

@cjwirth
Copy link
Author

cjwirth commented Jul 5, 2024

Another workaround that I've had to do (for a different library, but another one made by Google, lol) is to abstract it out so that only the top-level app target is the one that links the library.

So let's say you have OnboardingFramework and LoginFramework, and they both depend on GoogleSignIn. Instead, rework OnboardingFramework and LoginFramework so that they don't link and import GoogleSignIn. You'll give them their own protocols for the methods that you need to call from GoogleSignIn. Then in your top-level app target, you'll create implementations of the protocols you made, passing them into the frameworks when you need it.

Yes it's boilerplate, but it works.

@orbitekk
Copy link

The same problem occurs when you have App and Unit Testing Bundle and both import GoogleSignIn

@alvarhansen alvarhansen linked a pull request Sep 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issues that need to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants