143

When I try running my Xcode Project it fails with an error stating that I have duplicate symbols. I looked online where the find these duplicates but have had no luck:

enter image description here

Any ideas how to fix this?

4
  • 1
    it means you've got too much of BFAppLinkReturnToRefererView Commented Oct 10, 2014 at 16:24
  • Also, you might want to clean up your project a bit rather than linking to frameworks sitting on your desktop. :)
    – picciano
    Commented Oct 10, 2014 at 16:29
  • 1
    In my case I have added extern NSString * const tColor; in .h file and NSString const *tColor = @"#000022"; in two different .m classes.
    – ios_dev
    Commented Dec 19, 2017 at 11:33
  • 1
    You may find what you look for here stackoverflow.com/a/46678210/988941
    – MoOx
    Commented Feb 14, 2018 at 12:27

34 Answers 34

79

For me it helped to switch the "No Common Blocks" compiler setting to NO: It pretty much seems to make sense, the setting is explained here: What is GCC_NO_COMMON_BLOCKS used for?

4
  • You are the man! Just made a new xCode 7.3.1 project and the default setting is YES :(
    – Yaro
    Commented Jun 16, 2016 at 1:29
  • 6
    This option was switched on for me by Xcode's "Update project to recommended settings" window.
    – commscheck
    Commented Sep 5, 2016 at 5:07
  • You are the best Commented Jul 21, 2018 at 13:31
  • 2
    priceless tip, but doh didn't help in my case! :O
    – Fattie
    Commented Dec 20, 2018 at 20:05
71

From the errors, it would appear that the FacebookSDK.framework already includes the Bolts.framework classes. Try removing the additional Bolts.framework from the project.

2
  • 41
    how to? can you please guide me step by step
    – Imdad Ali
    Commented Dec 30, 2017 at 11:10
  • do you have any guide?
    – bdroid
    Commented Jan 20, 2021 at 14:01
54

Using Xcode 8, "Update project to recommended settings" option turned ON 'No Common Blocks' for my project.

Turning it back to OFF fixed everything up.

2
  • 2
    Update project to recommended settings, how do i do that? i mean from which menu? Commented Jan 27, 2017 at 4:42
  • @SazzadHissainKhan It's in your build settings.
    – Trip
    Commented Jan 31, 2017 at 17:01
53

I've messed up my pods while downgrading a pod and I've managed to resolve the issue with duplicate symbols for architecture arm64 by removing the pods and installing them again with:

pod deintegrate
pod install
5
  • I was using the Google Places SDK, integrated through CocoPods - 3.9.0, and this answer fixed my issue. Commented Aug 10, 2020 at 2:49
  • Thanks, you saved me a lot of headache Commented Aug 22, 2020 at 12:07
  • Note you have to specify the exact project you want to deintegrate. I would recommend dragging the project from xcode itself as opposed to from your file explorer... Had over 450 of these arm64 errors... Commented Sep 22, 2020 at 7:02
  • Helps with switching the "No Common Blocks" compiler setting to NO
    – Oranutachi
    Commented Nov 30, 2020 at 8:29
  • time-saving answer
    – hbk
    Commented Oct 3, 2021 at 18:42
28

Another Solution is to:

Select Project -> Target -> Build phase -> Compile source -> search for the file which is mentioned in the 3rd last error line (In your case BFAppLinkReturnToRefererView.o).

Then you will see either 1 or 2 files in search result.

Remove one of them and compile again. It should recompile now because there is only one file left and no more conflicts for build.

If that doesnt work the file probably has errors in it and you should remove all of them and then recompile. It should work again.

7
  • 5
    Extremely underrated answer, thanks for your help, Lukas! :)
    – patreu22
    Commented Oct 15, 2018 at 12:08
  • No Problem glad it sloved your problem :)
    – user9168386
    Commented Oct 15, 2018 at 12:13
  • THIS IS TRUUULY UNDERRATED
    – yoyo
    Commented Feb 25, 2021 at 2:27
  • none of the above worked and i was getting kinda desperate, but this was a hidden gem!
    – Robo
    Commented Mar 1, 2022 at 7:51
  • My problem is that I was switching from an included copy of a framework to cocoa pods, but I had forgotten that the framework was still being compiled in. I removed the framework's file from the compilation step, and the error went away! Thank you so much.
    – Nick K9
    Commented Apr 8, 2022 at 23:21
26

For me it was that i imported a file as a .m not a .h by mistake

2
  • That's LOL, but true ;D
    – Vladimir
    Commented Feb 13, 2017 at 11:58
  • this just happened to me.. I blame code completion for everyting
    – user426132
    Commented Jul 24, 2019 at 10:52
19

Below Patch work for me..:)

Step 1: Go to TARGETS -> Build Settings -> No Common Blocks -> No

Step 2: Go to TARGETS -> Build Settings -> enable testability -> No

Setting it back to NO solved the problem!

2
  • 2
    Step 2: Solved my problem. Thank you :)
    – Dorald
    Commented Apr 13, 2019 at 18:26
  • The enable testability was the issue for me! I did a lot of research to find that!!
    – cryptotheo
    Commented Nov 13, 2022 at 8:24
11

On upgrading to Xcode 8, I got a message to upgrade to recommended settings. I accepted and everything was updated. I started getting compile time issue :

Duplicate symbol for XXXX Duplicate symbol for XXXX Duplicate symbol for XXXX

A total of 143 errors. Went to Target->Build settings -> No Common Blocks -> Set it to NO. This resolved the issue. The issue was that the integrated projects had code blocks in common and hence was not able to compile it. Explanation can be found here.

11

If you are moving to Xcode 7 or 8 and are opening a really old project, I've encountered this problem:

in SomeConstFile.h

NSString * const kAConstant;

in SomeConstFile.m

NSString *const kAConstant = @"a constant";

Earlier versions of the compiler assumed that the definition in the header file was extern and so including SomeConstFile.h all over the place was fine.

Now you need to explicitly declare these consts as extern:

in SomeConstFile.h

extern NSString * const kAConstant;
3
  • 1
    Thanks for this! Was struggling with an issue with a constants.h file I was creating lol
    – Sung
    Commented May 22, 2017 at 17:14
  • 1
    Thank you for the answer I too was facing the same issue and your answer worked for me...
    – reetu
    Commented Jun 23, 2017 at 16:09
  • 1
    Thanks, i was struggling for this problem for past 3-4 hrs Commented Sep 8, 2017 at 20:49
9

This error happens when Linker is trying to link the obj files. Few reasons that i could think of for this error are:

  1. The duplicated Function/Class is defined at two different places/files in the project and only one of them was supposed to compile for any variation of build command. But somehow both those files got compiled in your project. So you need to check your if-else conditions or other dependencies which adds src files to the list of files needed to be compiled and remove the un-needed file for your particular build command.

  2. The duplicated Function/Class is defined accidentally at two different places/files in the project. Remove the wrong definition.

  3. Clean your OBJ directory before you build again, there could be some old obj files in there from your previous builds which might be causing this conflict.

P.S i am no expert, but this is how i solved this problem when i faced it. :)

4

Plz Change setting.

Step 1: Go to TARGETS -> Build Settings -> No Common Blocks -> No

Step 2: Go to TARGETS -> Build Settings -> enable testability -> No

0
3

You face this problem when you install FireBaseAnalytics via Swift Package Manager, and Google AdMobs SDK via CocoaPods, as guided by the official documentation. You end up with duplicated libraries.

My solution to this problem is installing both FireBaseAnalytics and Google AdMobs SDK via CocoaPods.

2

Well, some times when using SDK like FB or Libraries like Vuforia or GoogleAnalytics , adding sample projects may cause the problem that they're already including Frameworks and like so ,so you must make sure not repeating symbols you add manually while they're already included in samples

2

For me, the issue was the style of creation of const, that worked fine until this iOS8.. i had a few lines as:

int const kView_LayoutCount = 3;

in my .h file. Six lines like resulted in 636 linker files once common blocks was set to NO. (14k+ if YES). Moved the lines to .m after stripping .h of the value declaration and compilation was good to go.

Hope this helps others!

2

In my case reason was too stupid :

I had a Constant.h file where I had macros defined. I thought of doing NSString there. and did this :

NSString const *kGreenColor = @"#00C34E";

this caused the problem of Duplicate Symbols for Architecture arm64 and Linker command failed with exit code 1. Removing const NSString line worked for me.

2

check your include file, I had this issue because I accidentally #imported "filename.m" instead of "filename.h", autocorrect (tab) put an "m" not "h".

1
  • Thank you so much, I didn't realise I had made this mistake, was taking up all my time. Thanks again 👍 Commented Sep 17, 2019 at 9:53
2

The problem for me was I had manually included a framework but then also included that same framework in CocoaPods not knowing I did so. Once I removed one or the other, the problem went away

2

If someone is experimenting this working on Flutter, don't try to pod deintegrate, pod init.

How I solved is running flutter clean, flutter run -d [iOS Device]

Hope can help somebody.

1

From the errors, it would appear any Classes appear multiple time.Find and removed that Classes it will working.

Am creating AppDelegate.h and .m file creating multiple time. So this error will occur.Finally find and removed that classes it's working fine for me.

1

to solve this problem go to Build phases and search about duplicate file like (facebookSDK , unityads ) and delete (extension file.o) then build again .

1

Code

  • CrifanLibiOS.h
const int OPEN_OK = 0;
  • CrifanLibiOS.m
#import "CrifanLibiOS.h"
...
// use the const int value
  if (OPEN_OK == openResult){

and:

  • include by other ObjC file
    • openFileViewController.m
#import "CrifanLibiOS.h"

Error

ld: 6 duplicate symbols for architecture arm64

Reason

CrifanLibiOS.h be imported multiple time, and const int is redefined multiple time

Solution

for ObjC, const variable should change to:

  • implementation in xxx.m
    • CrifanLibiOS.m
#import "CrifanLibiOS.h"

const int OPEN_OK = 0;

...
// use the const int value
  if (OPEN_OK == openResult){
  • declaration in xxx.h, MUST with extern
    • CrifanLibiOS.h
extern const int OPEN_OK;
1

I was doing my tutorial, then I divided answers into different files, didn't mean to relate them to make a big program.

I didn't solve the problem until I commented out the remaining lines of the "main.cpp" file to make sure the program can run separately without the influence of it.

I'm not really sure about the principle of it, but I think it might be caused by a conflict of in fact multiple "main.cpp" files.

Just a little discovery from a first-year student, hope can help somebody.

1

As none of the provided answers solved the problem for me, I want to share this workaround:

  • Go to Targets -> {Your-App-Target} -> Build Settings -> Other Linker Flags
  • Replace -Objc with -ld64 or just add -ld64 if not existent
  • Run Clean Build Folder and build app again

Sources:

0

For me, I created a method called sampleMethod in ViewController_A and created the same method in ViewController_B too, It caused me this error, then i changed the method name in ViewController_B to secondSampleMethod. It fixed the error.

Seems like a Good feature to reduce the code and not to duplicate the same code in many places.

I tried changing the No Common blocks from Yes to No then enabling testability from Yes to No. It didn't worked. I Checked duplicate files also in build phases, but there is no duplicate files.

0

I got this issue because I was lazily defining a variable in my .m outside of a method, then in another .m file I was defining another variable with the same name outside a method. This was causing a global variable name duplicate issue.

0

I was able to resolve this error which said "158 duplicate symbols for architecture armv7, 158 duplicate symbols for architecture arm64" --- If this is what you are getting too, then it means you are trying to compile a file which is importing or inheriting a framework or static library having references to C++ code or files. An easy way to handle this would be to change the extension of your .m file to .mm. This is how it gets handled if you are using Objective C, not sure on Swift though.

Also in your build settings - you can update the "other linker flags" to -lc++

0

I got this issue when I had two files that had the same name on accident (large project, oops!)

Ironically they were actually the same file, I just had forgotten that I had already created one as a placeholder weeks earlier and gave it the same name again, haha!

0

Sometime It works with cache cleaning in Xcode using command+shift+k

Mine issue was that I have multiple files with same name, So I removed duplicate files, In console You can see file name Hope can help somebody.

0

I had this on a Flutter project after changing dependency versions. I had to do the following:

pod deintegrate
flutter clean
pod install