flipper icon indicating copy to clipboard operation
flipper copied to clipboard

Undefined symbols for architecture x86_64 (glog), w/ use_frameworks!, Hermes

Open moriyuu opened this issue 2 years ago • 17 comments

🐛 Bug Report

When I build my react-native app with Xcode I get the following error. I seem to be getting an error about glog in NotificationService, which is Dependencies in myapp.

Undefined symbols for architecture x86_64:
  "google::ErrnoLogMessage::ErrnoLogMessage(char const*, int, int, long long, void (google::LogMessage::*)())", referenced from:
      folly::fibers::StackCache::borrow(unsigned long) in libFlipper-Folly.a(GuardPageAllocator.o)
      folly::fibers::StackCache::StackCache(unsigned long, unsigned long) in libFlipper-Folly.a(GuardPageAllocator.o)
      folly::fibers::StackCache::~StackCache() in libFlipper-Folly.a(GuardPageAllocator.o)
  "google::InitVLOG3__(google::SiteFlag*, int*, char const*, int)", referenced from:
      folly::EventBase::~EventBase() in libFlipper-Folly.a(EventBase.o)
      folly::EventBase::SmoothLoopTime::setTimeInterval(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> >) in libFlipper-Folly.a(EventBase.o)
      folly::EventBase::loopBody(int, bool) in libFlipper-Folly.a(EventBase.o)
      folly::EventBase::nothingHandledYet() const in libFlipper-Folly.a(EventBase.o)
      folly::EventBase::bumpHandlingTime() in libFlipper-Folly.a(EventBase.o)
      folly::EventBase::terminateLoopSoon() in libFlipper-Folly.a(EventBase.o)
      folly::EventBase::SmoothLoopTime::SmoothLoopTime(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> >) in libFlipper-Folly.a(EventBase.o)
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
image

To Reproduce

I have enabled use_frameworks! (dependent library constraints), Hermes and Flipper are also enabled.

Podfile (excerpt) ↓. I have also added some workarounds in reference to other issues.

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target_version = '11.0'

platform :ios, target_version

target 'myapp' do
  use_frameworks! :linkage => :static

  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => true
  )

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  # https://github.com/facebook/flipper/blob/2e9ab310bd135e94b806916412d447c0e9ee3de9/react-native/ReactNativeFlipperExample/ios/Podfile#L30
  use_flipper!({ 'Flipper' => '0.150.0', 'Flipper-Folly' => '2.6.10', 'Flipper-DoubleConversion' => '3.2.0', 'Flipper-Glog' => '0.5.0.3', 'Flipper-PeerTalk' => '0.0.4', 'OpenSSL-Universal' => '1.1.1100' })

  # https://fbflipper.com/docs/getting-started/ios-native/
  #
  # If you use `use_frameworks!` in your Podfile,
  # uncomment the below $static_framework array and also
  # the pre_install section.  This will cause Flipper and
  # it's dependencies to be built as a static library and all other pods to
  # be dynamic.
  #
  # NOTE Doing this may lead to a broken build if any of these are also
  #      transitive dependencies of other dependencies and are expected
  #      to be built as frameworks.
  $static_framework = [
    'FlipperKit', 'Flipper', 'Flipper-Folly',
    'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion',
    'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit',
    'CocoaLibEvent', 'OpenSSL-Universal', 'boost-for-react-native', 'Flipper-Fmt',
  ]
  pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    installer.pod_targets.each do |pod|
      if $static_framework.include?(pod.name)
        def pod.build_type;
          Pod::BuildType.static_library
        end
      end
    end
  end

  post_install do |installer|
    installer.pods_project.targets.each do |target|
      # https://github.com/facebook/react-native/issues/32451#issuecomment-1162994787
      if target.name == "RCT-Folly"
        target.build_configurations.each do |config|
          config.build_settings['HEADER_SEARCH_PATHS'] = "\"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/libevent/include/\" \"$(PODS_ROOT)/fmt/include\" \"$(PODS_ROOT)/glog\""
          config.build_settings['OTHER_LDFLAGS'] = "\"-Wl,-U,_jump_fcontext\" \"-Wl,-U,_make_fcontext\""
        end
      end
    end

    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

install pods and build RN app with xcode.

Environment

M1 pro Flipper Desktop version: 0.150.0 XCode version: 13.3 react: 17.0.2 react-native: 0.66.3 flipperkit version in Pods: 0.150.0

moriyuu avatar Jun 29 '22 01:06 moriyuu

I'm dealing with a similar issue. Here's a quote from https://rnfirebase.io/

"Note use_frameworks is not compatible with Flipper, Hermes, React Native New Architecture or react-native 0.69.0. There is already a patch-package patch available for 0.69.0 that makes it work with and without Hermes and it will be released with 0.69.1. Community support to help fix use_frameworks support for Hermes and New Architecture is welcome!"

It looks like they just released 0.69.1 a few hours ago, but according to other posts in react-native issues it looks like now there are different issues with installing libraries at https://github.com/facebook/react-native/issues/34101#issue-1288993058 and https://github.com/facebook/react-native/issues/34102.

annieneedscoffee avatar Jun 29 '22 23:06 annieneedscoffee

@annieneedscoffee Thanks for your comment. As long as we continue to use flipper, we can't seem to enable use_frameworks, can we?

moriyuu avatar Jul 01 '22 10:07 moriyuu

I guess not for now. I think they're still working on the fix. I'm going to check back in a few days and see if they have provided an update.

annieneedscoffee avatar Jul 01 '22 18:07 annieneedscoffee

I'm seeing the same errors here with basically the same Podfile. Has anyone found a workaround yet?

amhinson avatar Jul 19 '22 14:07 amhinson

Same here. Screenshot 2022-07-28 at 13 22 18

streem-ua avatar Jul 28 '22 10:07 streem-ua

@Kudo apologies for just randomly tagging you in on an issue, but this is the build error stopping Flipper from working with use_frameworks. There's confirmation of the same here https://github.com/invertase/react-native-firebase/issues/6425#issuecomment-1226541813

Perhaps you have the wisdom to know semi-immediately what this type of error usually means and how to fix it. I see it as a likely linker path issue, but I'm not sure exactly how to fix

The Podfile above looks like it matches the documentation in this repo https://fbflipper.com/docs/getting-started/ios-native/#cocoapods

So this is the leading edge of "getting use_frameworks working in the main react-native components", if this can be fixed

I'll be in the area off and on giving it a shot myself, but you sniped the Hermes issue so quickly I couldn't resist tagging you. Cheers

mikehardy avatar Aug 24 '22 23:08 mikehardy

@mikehardy i'm afraid i can help here. as far as i know flipper doesn't support use_frameworks from very early days. i tried to fix some but there're many issues, e.g. incorrect double quoted imports. i think to support use_frameworks for flipper. the source code and podspecs should be reorganized much just like the case of use_frameworks + fabric.

Kudo avatar Aug 26 '22 12:08 Kudo

That background info (that you tried, and what the real scope of solution is), is still great information, thanks @Kudo.

Flipper team, the documentation currently states how to get use_frameworks to work on Flipper but those documents do not result in a successful build. Is this on your radar at all for a fix?

My motivation is that react-native-firebase requires use_frameworks now, and I'd like to get this to work out of the box for people. Going by npmjs stats we appear to represent about 25% of all react-native usage (266K/week vs 1000K/week) so perhaps it is worth a look?

mikehardy avatar Aug 26 '22 12:08 mikehardy

@mikehardy It doesn't seem like issues on this repo get regularly checked by anyone, perhaps it would get some attention if linked to an issue on the main react-native repo?

evelant avatar Aug 28 '22 11:08 evelant

I'll bring it up on discord and see what happens

mikehardy avatar Aug 28 '22 13:08 mikehardy

For what it's worth, I did bring this up on discord () and the response for the moment is that the team is aware and it needs effort, but there does not appear to be a commitment to a deadline or anything. So this may sit for a while

mikehardy avatar Sep 18 '22 13:09 mikehardy

Bummer, I am experiencing the same issue. Looks like I will no longer use flipper in React Native iOS app for a while...

pang0018 avatar Sep 19 '22 20:09 pang0018

Facing same issue for IOS in React-Native after upgrading to 0.70 and enabling useFrameworks! :linkage => :static (https://rnfirebase.io/).

sairajKalkundre avatar Sep 21 '22 15:09 sairajKalkundre

@sairajKalkundre Flipper does not work with any form of use_frameworks! in your Podfile, as clearly stated in all parts of this issue.

For future readers: until you see some discussion of a patch to try, or you are proposing a patch to try, Flipper will simply not work with use_frameworks and of course you will experience the same issue. Posting the same is a sort of "metoo" and is best handled as a reaction (thumbs up or similar) on this issue itself, way up at the top.

Thanks

mikehardy avatar Sep 21 '22 15:09 mikehardy

@mikehardy I have edited my comment.

sairajKalkundre avatar Sep 21 '22 15:09 sairajKalkundre

@sairajKalkundre have you been albe to fix this irritating issue?

fondue-tech avatar Oct 20 '22 08:10 fondue-tech

Temporary workaround from another thread:

  • https://github.com/facebook/flipper/issues/4278#issuecomment-1296942100

KrisLau avatar Jan 04 '23 16:01 KrisLau