React-native: iOS linker error adding Google Nearby Messages API to XCode project

Created on 16 Oct 2017  Â·  4Comments  Â·  Source: facebook/react-native

Is this a bug report?

YES

Environment

Environment:
OS: macOS High Sierra 10.13
Node: 8.6.0
Yarn: 1.0.2
npm: 5.3.0
Watchman: 4.7.0
Xcode: Xcode 9.0 Build version 9A235
Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
react: 16.0.0-beta.5 => 16.0.0-beta.5
react-native: 0.49.3 => 0.49.3

Target Platform: iOS (10.0)

Steps to Reproduce

  1. react-native init SampleProject
  2. Follow Google Nearby Messages API installation guide (https://developers.google.com/nearby/messages/ios/get-started) to add Messaging API to react native XCode project
  3. compile XCode workspace project

Expected Behavior

There should not be any duplicated symbols between Google Nearby Messages API implementations with React ThirdParty implementation,
or a work around to avoid the duplication of these symbols to use Google Nearby API in a react native project.

Actual Behavior

Linker error for duplicated symbols.

duplicate symbol __ZN6google10AddLogSinkEPNS_7LogSinkE in:
    /Users/dimutu.k/Library/Developer/Xcode/DerivedData/nearby-axzoinmlhtvrrpfvlpxeomerfvml/Build/Products/Debug-iphoneos/libReact.a(logging.o)
    /Work/WINK/nearby/ios/gns/NearbyMessages/Libraries/libGNSMessages.a(logging.o)
duplicate symbol __ZN6google13RemoveLogSinkEPNS_7LogSinkE in:
    /Users/dimutu.k/Library/Developer/Xcode/DerivedData/nearby-axzoinmlhtvrrpfvlpxeomerfvml/Build/Products/Debug-iphoneos/libReact.a(logging.o)
    /Work/WINK/nearby/ios/gns/NearbyMessages/Libraries/libGNSMessages.a(logging.o)
ld: 2 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Reproducible Demo

Please run

npm install
cd ios
pod install

GNSMessageSampleProject.zip

Stale

Most helpful comment

This is due to duplicate symbols in the glog third party code which seems to also be embedded in NearbyMessages.

A workaround is to rename the symbols in the glog in the React project. You can do this by running these two command:

grep -rl --include \*.h --include \*.cpp --include \*.cc --include \*.in AddLogSink node_modules/react-native/third-party/ | xargs sed -i '' 's/AddLogSink/ReactAddLogSink/g'
grep -rl --include \*.h --include \*.cpp --include \*.cc --include \*.in RemoveLogSink node_modules/react-native/third-party/ | xargs sed -i '' 's/RemoveLogSink/ReactRemoveLogSink/g'

This searches for instances of AddLogSink and RemoveLogSink and replaces them with ReactAddLogSink and ReactRemoveLogSink respectively. As this is done inside node_modules I recommend adding these to your postinstall script to avoid them being overridden every install.

All 4 comments

This is due to duplicate symbols in the glog third party code which seems to also be embedded in NearbyMessages.

A workaround is to rename the symbols in the glog in the React project. You can do this by running these two command:

grep -rl --include \*.h --include \*.cpp --include \*.cc --include \*.in AddLogSink node_modules/react-native/third-party/ | xargs sed -i '' 's/AddLogSink/ReactAddLogSink/g'
grep -rl --include \*.h --include \*.cpp --include \*.cc --include \*.in RemoveLogSink node_modules/react-native/third-party/ | xargs sed -i '' 's/RemoveLogSink/ReactRemoveLogSink/g'

This searches for instances of AddLogSink and RemoveLogSink and replaces them with ReactAddLogSink and ReactRemoveLogSink respectively. As this is done inside node_modules I recommend adding these to your postinstall script to avoid them being overridden every install.

Thanks for the workaround!

Unfortunately, I'm not having any luck using it as a postinstall hook: it seems that node_modules/react-native/third-party doesn't even exist after npm install. Instead, third-party is installed lazily when executing react-native run-ios.

I found out the same thing. It worked originally as I’d done a build before
running “yarn install”. You could likely work around that issue by running
the third party script before the workaround on postinstall.

On Wed, 15 Nov 2017 at 23:21, Brian Nicholson notifications@github.com
wrote:

Thanks for the workaround!

Unfortunately, I'm not having any luck using it as a postinstall hook: it
seems that node_modules/react-native/third-party doesn't even exist after npm
install. Instead, it's installed lazily when executing react-native
run-ios.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/facebook/react-native/issues/16406#issuecomment-344762224,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAF7LJNF8w6ArsVm5rgJ20Yhbi3JHlquks5s23HwgaJpZM4P6FNz
.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings