React-native: [iOS] Undefined symbols for architecture arm64: "_RCTSetLogFunction"

Created on 14 Sep 2015  ·  73Comments  ·  Source: facebook/react-native

Hello,
I have this linking error:
Undefined symbols for architecture arm64:
"_RCTSetLogFunction", referenced from:
-[PropertyFinderTests testRendersWelcomeScreen] in PropertyFinderTests.o

When i try to compile the default project on iOS. (using react-native init)

iOS Locked

Most helpful comment

Same issue here. In my case, this is caused by missing 'libReact.a' in the AwesomeProjectTests link path.

Symptom

Fresh 'react-native init AwesomeProject'. Load it with Xcode and build failed at AwesomeProjectTest target for iphone device with the errors:

"_RCTSetLogFunction", referenced from:
-[AwesomeProjectTests testRendersWelcomeScreen] in AwesomeProjectTests.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is because libReact.a is not at the 'AwesomeProjectTests' target build Phases -> 'Link Binary With Libraries'

Workaround

Manually add libReact.a to 'AwesomeProjectTests' target 'Link Binary With Libraries'.

  1. Open Xcode project page.
  2. Select Targets->"AwesomeProjectTests"
  3. Select 'Build Phases'-> 'Link Binary With Libraries'
  4. Press '+' to add item.
  5. Select 'Workspace'->libReact.a, hit 'Add'
  6. Rebuild the project, and build succeeded.

[email protected]
Xcode Version 7.0 (7A220)
iOS: 9.0 (13A344)

All 73 comments

If anything broke this it might have been my commit: https://github.com/facebook/react-native/commit/19f922aa806b027348d9243b0085126fe553e266

@kmagiera @brentvatne @ide Are you hitting this as well? My Xcode is unfortunately busted, reinstalling now.

@javache is in London and it's quite late here. Can you unblock yourself by commenting out the test code until we can repro?

@javache is with me at at-scale conf in SJ, he promised to take a look

Awesome, thank you @kmagiera and @javache!

Just did react-native init MyAwesomeApp and the app builds from Xcode and runs on an iPhone 6 simulator. What device are you using?

@Javanaise - which version of Xcode? Only 6.3+ are supported

@mkonicek A real iphone 6
@brentvatne 6.4

@Javanaise - try pressing ⌘+k to clean the build and run it again

@brentvatne did a Clean and a Clean build folder, still fails

@Javanaise - have you tried in the simulator?

@brentvatne it's working in the simulator

@Javanaise - what OS version?

Same problem on iphone 6 ios 8.3. It is working on the simulator.

Also what simulator? Make sure it's 5s or newer which runs the x86_64 libs.

@brentvatne os x ? 10.10.5
@ide I used iphone 6 for the simulator, and it built.
I only have a problem with both my iphone 6 and 5 real phones.

The same problem
iPhone 6
iOS 8.4
OS X El Capitan 15A282b

Compiling fine for me (even after cleaning) w/actual iPhone 6, Xcode 7 GM, El Cap beta 8. Wonder if Xcode is the issue here...

Also same problem
Xcode Version 6.4 (6E35b)
iphone6 plus
ios 8.4.1
OSX 10.10.5

Same here,

Xcode 7 GM
iphone6
ios 8.4.1
OSX 10.10.5

fails only on real device.

as a quick workaround, removing tests makes this go away

I can repro this when building the SampleApp for testing for iPhone 6 using Xcode 7 GM. Investigating.

The problem seems that Xcode's dead code stripping removes the RCTSetLogFunction, since it's not being called anywhere. Disabling "Dead Code Stripping" from your main target's build settings for Debug builds will disable the build error.

This method was changed in https://github.com/facebook/react-native/commit/b998e5a7b74905b30b1137a02e14cd5e6f97fccc

i have some error,but only remove test target,it's ok!

The solution @javache provided worked for me after encountering this error running on a physical device from Xcode 7 after upgrading my existing app to React Native v0.11.0. Thanks for opening this issue @Javanaise!!

Disabling "Dead Code Stripping" let me run on my physical device.
Thanks @javache!

Same issue here. In my case, this is caused by missing 'libReact.a' in the AwesomeProjectTests link path.

Symptom

Fresh 'react-native init AwesomeProject'. Load it with Xcode and build failed at AwesomeProjectTest target for iphone device with the errors:

"_RCTSetLogFunction", referenced from:
-[AwesomeProjectTests testRendersWelcomeScreen] in AwesomeProjectTests.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is because libReact.a is not at the 'AwesomeProjectTests' target build Phases -> 'Link Binary With Libraries'

Workaround

Manually add libReact.a to 'AwesomeProjectTests' target 'Link Binary With Libraries'.

  1. Open Xcode project page.
  2. Select Targets->"AwesomeProjectTests"
  3. Select 'Build Phases'-> 'Link Binary With Libraries'
  4. Press '+' to add item.
  5. Select 'Workspace'->libReact.a, hit 'Add'
  6. Rebuild the project, and build succeeded.

[email protected]
Xcode Version 7.0 (7A220)
iOS: 9.0 (13A344)

same issue here,

the solution of @javache works for me too.

I didn't try the dead code stripping but the solution by @bidatacoder worked fine for me. Thanks :)

How do you disable 'Dead Code Stripping', I'm new to Xcode unfortunately, and am having the same problem.

@jonolock91, you can get to the build settings by clicking on the main xcodeproj file (the one with the blue icon) in the sidebar. There will be a search bar in the now-opened build settings pane so you can start typing "Dead code stripping" to filter out the other settings. Expand the Dead Code Stripping setting and change debug to NO.

image

@tealtail thanks for the help, that has now worked for me too! :)

Thanks @bidatacoder

Dead Code Stripping trick worked for me.

+1 Dead Code Stripping

Dead Code Stripping trick worked for me as well. :+1: @tealtail

Dead code stripping worked for me.

Dead code stripping worked for me, too.

Was having the same issue. @javache's solution worked for me. Thanks, appreciate it!!

+1 here, @javache's solution worked for me too. Big thanks!

+1 on @javache solution

+1 Dead Code Stripping

meet this too

Yes, "dead strip trick" works for me too.
But, how could I give up "dead strip" which is a crucial feature for an app?

@bidatacoder your workaround seems not working :(

checkout ur net-work, try to connect ur mac with proxy and change the localhost of jsCodeLocation to ur ip

Setting Dead Code Stripping to no worked for me. Thx

screen shot 2015-12-02 at 4 51 52 pm

+1 on @bidatacoder's solution, allows me to keep dead code stripping as YES and still create a successful release build.

+1 for @bidatacoder's solution. I had the exact same issue detailed above.

I'm seeing this error and I had Dead Code Stripping set to NO. Any other ideas?

+1 Thank you for @tealtail's solution. It worked.

@bidatacoder's solution worked! https://github.com/facebook/react-native/issues/2685#issuecomment-142137371

Thanks!

Is "set Dead Code Stripping to No" or @bidatacoder solution better ?

@Mokto - I believe bigdatacoder's solution is better as it allows the app to strip out unneeded code from the build.

via Apple's docs

For statically linked executables, dead-code stripping is the process of removing unreferenced code from the executable file. If the code is unreferenced, it must not be used and therefore is not needed in the executable file. Removing dead code reduces the size of your executable and can help reduce paging.

Disable Dead Code Stripping in the build setting fix my issue. Thanks @javache

'Dead code Stripping' Disabling fixes this issue, Thanks @javache.

If I remove 'Dead Code Stripping' on the release build, will I have logs when I submit my app to iTunes connect?

I tried to use @bidatacoder's method, but I do not see libReact.a as a library that I can add.

For anyone poking with this and having issues with the @bidatacoder's method:

You have to select the TESTS target (that is <AppName>Tests) and add the libReact.a there, not your actual app's target, which has the libReact.a already!

@avioli @bidatacoder Thanks! This works better than turning down dead code stripping!

Just in case someone is doesn't know how to add the extra configuration mentioned by @avioli, in Xcode:

  1. Select your the test target <AppName>Tests
  2. Select Build Phases
  3. Under Link Binary with Libraries, click the + icon and then add libReact.a. Then build again.

Should work. Thanks @avioli

Could you submit a pull request that changes the project generator to do this by default? Thanks!

I had the same issue. However, it was caused by renaming the app. I fixed it by doing a project wide search and replacing all occurrences of the name. I also had to change a few directory and file names.

Same Issue here but adding libReact.a to my test target do the trick! :)

Same issue and disabling Dead Code Stripping didn't solve the problem whereas @bidatacoder solution worked fine for me 👍

HI,
I have the same problem but
-it says architecture i386 instead of arm64
-it only happens when i choose iphone 5/4s simulators; other version such as 5s/6/6s don't have the problem

I tried the dead code stripping and add libReact.a to TESTS, both of them are not working for me.

Have anyone had the same problem?

update:
After many hours of googling and trying, I finally fixed it.
After disabling dead code stripping and adding libReact.a to Tests, I have to add -lc++ in other linker flags.

Here are some of the things that DIDN'T work for me:
-changing Architectures/Valid Architectures
-set No to build active architectures only
-remove test host

Hope it helps.

For anyone having this problem, make sure you add the -lc++ flag to your <AppName>Tests target and not your normal target (where it probably already exists.)

@zdol Tests has no 'Other Linker Flags' option

In Build Settings All, I found that option, and after add -lc++ flag, it works! Thank you @zdol !

@czl1378 it's work for me thanks

Here is a screenshot, thanks @czl1378

screenshot_2016-12-20 19 08 31_7naokg

I have been struggling with this for a while after upgrading to rn0.39, and the answer @czl1378 and @benjaminb10 is correct. you need to add other linker flags.

+1 -- Adding the flags fixed the build errors for me on 0.40.0

@benjaminb10 +1 adding that flag fixes the issue

Under Link Binary with Libraries, click the + icon and then add libReact.a. Then build again.

For me, vice versa, removing libReact.a helped me and my tests and my app runs both on simulator and device.

I'm using CocoaPods 1.2.0 and React Native 0.42.0. When I try to archive a release build, the error occurs.

It seems that your solutions won't work in my situation. Any ideas?

@bidatacoder 's solution didnt work for me :-( I don't have 'Workspace'->libReact.a ... the closest I have is libcxxreact.a

Any ideas?

Was this page helpful?
0 / 5 - 0 ratings