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

iOS: Undefined symbols for architecture x86_64/arm64 #41

Closed
WNemencha opened this issue Apr 20, 2021 · 13 comments
Closed

iOS: Undefined symbols for architecture x86_64/arm64 #41

WNemencha opened this issue Apr 20, 2021 · 13 comments
Assignees
Labels
awaiting-reply bug Something isn't working

Comments

@WNemencha
Copy link

WNemencha commented Apr 20, 2021

Hello, DataDog team! :)

Describe what happened:
When trying to compile our app for iOS (react-native app), with freshly yarn added dd-sdk-reactnative, it fails with the following error:

Undefined symbols for architecture x86_64:
  "static Foundation.JSONEncoder.OutputFormatting.withoutEscapingSlashes.getter : Foundation.JSONEncoder.OutputFormatting", referenced from:
      static (extension in Datadog):Foundation.JSONEncoder.default() -> Foundation.JSONEncoder in libDatadogSDK.a(JSONEncoder.o)
  "Network.NWPath.isConstrained.getter : Swift.Bool", referenced from:
      closure #2 () -> Swift.Bool? in closure #1 (Network.NWPath) -> () in Datadog.NWPathNetworkConnectionInfoProvider.init(monitor: Network.NWPathMonitor) -> Datadog.NWPathNetworkConnectionInfoProvider in libDatadogSDK.a(NetworkConnectionInfoProvider.o)
  "(extension in Foundation):__C.NSFileHandle.readToEnd() throws -> Foundation.Data?", referenced from:
      Datadog.File.read() throws -> Foundation.Data in libDatadogSDK.a(File.o)
  "(extension in Foundation):__C.NSFileHandle.seekToEnd() throws -> Swift.UInt64", referenced from:
      Datadog.File.append(data: Foundation.Data) throws -> () in libDatadogSDK.a(File.o)
  "(extension in Foundation):__C.NSFileHandle.write<A where A: Foundation.DataProtocol>(contentsOf: A) throws -> ()", referenced from:
      Datadog.File.append(data: Foundation.Data) throws -> () in libDatadogSDK.a(File.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Steps to reproduce the issue:

  1. Install dd-sdk-reactnative in a react-native v0.63.4 project (ios/android)
  2. cd ios/ && pod install
  3. react-native run-ios

Describe what you expected:

I expected the build to succeed, as the one for Android does.

Additional context:

  • "dd-sdk-reactnative": "^1.0.0-alpha5",
@WNemencha WNemencha added the bug Something isn't working label Apr 20, 2021
@0xnm
Copy link
Member

0xnm commented Apr 21, 2021

Hello @WNemencha! Can you please check if the same happens if you try to build our sample app on your machine? Also can you please tell which XCode version you are using?

@WNemencha
Copy link
Author

WNemencha commented Apr 21, 2021

Hey @0xnm,

I've just tried to run your sample app and it seems to be compiling and running but I still can't receive any log inside my test DataDog account (in the RUM apps section).

I've been trying to fix this issue since yesterday and now that I think about it, it looks more like a Swift error to me, currently investigating ;). About XCode: Version 12.4 (12D4e)

@buranmert buranmert self-assigned this Apr 23, 2021
@buranmert
Copy link
Contributor

hi @WNemencha 👋
thanks for reporting the issue!
the issue seems to be caused by a fix in React Native.
we raised facebook/react-native#31417 to fix this in React Native template but this may take time.

Problem

Swift frameworks can't be linked statically in pure Obj-C projects. React Native was keeping an empty Swift.swift file in its template project as a workaround, that makes it a Swift&Obj-C mixed target so that it works. the fix i mentioned above removed this file and set custom Library Search Paths for the compiler to find required Swift symbols during linking. however, it seems to be set to a wrong location and can't find some of the Swift symbols that our SDK relies on.

Fix

please check that Library Search Paths in your {MyApp} project points to the following

LIBRARY_SEARCH_PATHS = (
  "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
  "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
  "\"$(inherited)\"",
);

if so, can you please replace $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME) with /usr/lib/swift/ as seen in the screenshot below?

Screenshot 2021-04-23 at 17 51 24

let me know if that works (or not!) for you and/or if you have any other questions

@WNemencha
Copy link
Author

You know what ? It works! Thanks dear @buranmert, you saved the sprint :)

@buranmert
Copy link
Contributor

@WNemencha good news 👍
i'm closing the issue as the issue is solved

@buranmert buranmert changed the title Undefined symbols for architecture x86_64 (osx/ios) iOS: Undefined symbols for architecture x86_64/arm64 Apr 29, 2021
@buranmert buranmert pinned this issue Apr 29, 2021
@papaschmidt
Copy link

I have been getting the exact same issue. While it will build after making the change listed in this issue, the app just closes out immediately afterwards when you attempt to load it.

'/usr/local/lib/libswiftCore.dylib' (no such file), '/usr/lib/libswiftCore.dylib' (no such file) from the Output

I've tried going to Build Settings in the target and changing Always Embed Swift Standard Libraries to Yes, but that doesn't seem to help here. Any ideas what I need to do to get this working?

@buranmert
Copy link
Contributor

hi @papaschmidt

i guess Always Embed Swift Standard Libraries shouldn't be needed as Swift libraries should already exist in iOS system images.

can you tell me which React Native, Xcode and iOS version you are using?
does your project contain Swift code as well?
has it ever worked before (e.g: with an older Datadog SDK or Xcode version) ?

@papaschmidt
Copy link

Hello @buranmert ,

I am on the following:

react-native: 0.64.2
Xcode: Version 13.1 (13A1030d)
iOS: I am doing testing on 15.

We don't have any custom swift code that we wrote in this code base, however, some of our 3rd party libraries might have swift code.

This is our first attempt at integrating DataDog SDK into our project as we're looking to add it to our app for logging, so I haven't gotten it to work yet. I did have to add a USER_DEFINED property SWIFT_VERSION to 5.0 to get it to install the pods, but I'm not sure if that is relevant to this.

@sregg
Copy link

sregg commented Nov 18, 2021

I thought this solution #41 (comment) for me didn't work until I realized I was looking at my Target's Build Settings and not my App's.
Thought I'd share that if others make the same mistake.

@papaschmidt
Copy link

Hello,

Our team was able to figure this out. For anyone who runs into this issue in the future. You need to have a bridging header in your react-native project. You just need to add an empty swift file to your project and during the process of it being added xCode will ask you if you want to create a bridging header - just click yes.

@quachdev
Copy link

quachdev commented Jan 10, 2022

@papaschmidt I am running into this issue now. We have already created a bridging header in the project.

Is the current solution still to replace $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME) with /usr/lib/swift/?

That seemed to work when changing it.

Ideally we don't have to change these settings as I have had bad experiences keeping track of these core tooling changes for specific dependencies. What happens in the future if we were to bring on another dependency and it doesn't work because we replaced the default search path?

Will there be a solution in the near future where we don't have to change the search paths in Xcode?

@buranmert
Copy link
Contributor

@quachdev $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME) was introduced in React Native in order to solve the Swift-only libraries (e.g: Datadog iOS SDK) problem without a bridging header. However, it doesn't work as that path has the wrong set of symbols.
AFAIK the only way to solve this is changing it to /usrl/lib/swift as it seems to be what's actually needed.

we raised a PR in React Native repo to fix the issue for everyone but it didn't get enough attention unfortunately.

@rplankenhorn
Copy link

rplankenhorn commented Aug 8, 2022

FYI, the LIBRARY_SEARCH_PATHS fix doesn't appear to work with the latest versions of the packages:

"react-native": "0.67.4",
"@datadog/mobile-react-native": "1.0.0",
"@datadog/mobile-react-navigation": "1.0.0",
datadogSdkPath = resolve_transitive_dependency(__dir__, '@datadog/mobile-react-native')
pod 'DatadogSDKReactNative', :path => "#{datadogSdkPath}"
pod 'DatadogSDKBridge', '0.5.5'
pod 'DatadogSDK', '1.11.1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-reply bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants