49

Getting following error when try to use Layar SDK in my existing app. How can I solve this?

Ld /Users/pnawale/Library/Developer/Xcode/DerivedData/hub-afxxzaqisdfliwbzxbixsaifljcl/Build/Products/Debug-iphoneos/hub.app/hub normal armv7
    cd /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub
    setenv IPHONEOS_DEPLOYMENT_TARGET 5.0
    setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -L/Users/pnawale/Library/Developer/Xcode/DerivedData/hub-afxxzaqisdfliwbzxbixsaifljcl/Build/Products/Debug-iphoneos -L/Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/ZBarSDK -L/Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/Infosound/Lib -L/Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/CrittercismSDK -L/Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub -L/Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/UserVoiceSDK-2.0.4 -L/Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/Libraries -F/Users/pnawale/Library/Developer/Xcode/DerivedData/hub-afxxzaqisdfliwbzxbixsaifljcl/Build/Products/Debug-iphoneos -F/Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub -filelist /Users/pnawale/Library/Developer/Xcode/DerivedData/hub-afxxzaqisdfliwbzxbixsaifljcl/Build/Intermediates/hub.build/Debug-iphoneos/hub.build/Objects-normal/armv7/hub.LinkFileList -dead_strip -ObjC -all_load -fobjc-arc -fobjc-link-runtime -miphoneos-version-min=5.0 -lMPOAuthMobile -lsbjson-ios -framework LayarSDK -framework Social -framework AddressBook -framework AddressBookUI -framework UIKit -framework QuartzCore -framework Twitter -framework SystemConfiguration -framework Security -framework OpenAL -framework OpenGLES -framework MessageUI -framework MediaPlayer -framework Foundation -framework CoreGraphics -lc++ -framework CoreTelephony -framework CoreVideo -framework CoreMotion -framework CoreMedia -framework CoreLocation -framework CoreData -framework CoreAudio -framework CFNetwork -framework AVFoundation -framework AudioToolbox -lxml2 -liconv -lz -framework MobileCoreServices -lzbar -linfosound -lCrittercism_v3_4_6 -lUserVoice -o /Users/pnawale/Library/Developer/Xcode/DerivedData/hub-afxxzaqisdfliwbzxbixsaifljcl/Build/Products/Debug-iphoneos/hub.app/hub

duplicate symbol _jpeg_free_large in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemname.o)
duplicate symbol _jpeg_free_small in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemname.o)
duplicate symbol _jpeg_get_large in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemname.o)
duplicate symbol _jpeg_get_small in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemname.o)
duplicate symbol _jpeg_mem_available in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemname.o)
duplicate symbol _jpeg_mem_init in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemname.o)
duplicate symbol _jpeg_mem_term in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemname.o)
duplicate symbol _jpeg_open_backing_store in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemname.o)
duplicate symbol _jpeg_free_large in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemnobs.o)
duplicate symbol _jpeg_free_small in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemnobs.o)
duplicate symbol _jpeg_get_large in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemnobs.o)
duplicate symbol _jpeg_get_small in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemnobs.o)
duplicate symbol _jpeg_mem_available in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemnobs.o)
duplicate symbol _jpeg_mem_init in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemnobs.o)
duplicate symbol _jpeg_mem_term in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemnobs.o)
duplicate symbol _jpeg_open_backing_store in:
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemansi.o)
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jmemnobs.o)
duplicate symbol _main in:
    /Users/pnawale/Library/Developer/Xcode/DerivedData/hub-afxxzaqisdfliwbzxbixsaifljcl/Build/Intermediates/hub.build/Debug-iphoneos/hub.build/Objects-normal/armv7/main.o
    /Users/pnawale/Documents/Paresh/Yamaha_iPhone/Code/Final/hub/LayarSDK.framework/LayarSDK(jpegtran.o)
ld: 17 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Vishal
  • 8,246
  • 6
  • 37
  • 52
Paresh
  • 993
  • 1
  • 7
  • 15

16 Answers16

123

This can happen if you accidentally #import a .m file instead of the .h!

Ruddy
  • 9,795
  • 5
  • 45
  • 66
Adrian Bigland
  • 1,439
  • 1
  • 13
  • 8
88

Generally, this kind of error occurs due to duplicate classes and xibs in your project folder. For example, in my project I had some class files duplicated(.h/.m files). You can see these duplicate classes under target->Build phases->compile sources.

Just look and remove extra classes. Problem will be solved.

Hyperbole
  • 3,917
  • 4
  • 35
  • 54
Vishal
  • 8,246
  • 6
  • 37
  • 52
  • 1
    Also check these discussion: http://stackoverflow.com/questions/15460481/ld-871-duplicate-symbols-for-architecture-armv7-clang-error-linker-command-f & http://stackoverflow.com/questions/6429494/undefined-symbols-for-architecture-armv7 – Vishal May 08 '13 at 03:16
  • What seemed odd to me is that both of the duplicates in all but one case came out of the `Layar.SDK` framework. The other duplicate is of `main` - which is provided by the OP's app and Layar. I wonder whether Layar.SDK is being used in the way it is intended? If so, this very much looks like their dogfood, and their support forum might be a good place to ask - afterall, the OP is paying them €2.5k per app per annum. – marko May 08 '13 at 08:40
  • 4
    What if my project has over 500 classes? >.>; – Ky - Dec 18 '15 at 21:48
  • @BenLeggiero s comment. – Daniel Barde Nov 23 '18 at 18:13
  • This would also work for Duplicate symbols for architecture x86_64 – vofili Apr 24 '20 at 02:47
52

Happens with static variables in a header file (header file included in more than one implementations file).

Jeff Lawson
  • 541
  • 4
  • 5
  • 6
    To help those like myself who didn't understand this at first: you have non-const variables being declared in a .h file that you are including in more than one place. You can't do this. To fix, change your static (non-const) variables to declarations using extern, and then define them in just one of the .cpp files where you include the .h – Matthew Herbst Apr 17 '14 at 15:58
  • This was my issue. Strangely it ONLY happened in emulation -- built fine on the device. (???) – Gabriel Jensen Oct 02 '14 at 18:46
  • 1
    This was my issue. Thanks for the advice, I never would have found that otherwise. +1 – Sev Jan 23 '15 at 22:48
19

I was getting this error because I used the Xcode recommended warning flags. GCC_NO_COMMON_BLOCKS = YES was causing the issue. Setting this back to NO fixed it for me.

pulse4life
  • 1,006
  • 10
  • 13
7

This error can also be caused if you have cyclic imports.... lets suppose you have VC1.h, VC2.h, and VC3.h

examples that will cause the error: (all are the .h files)

  • If VC2 imports VC1 and VC1 imports VC2
  • If VC1 imports VC2 and VC2 imports VC3 and VC3 imports VC1

solution:

  • import inside the .m instead of the .h
  • if the .h needs that class use @class (nameOfClass); instead of importing the .h

Be careful when using #import, only import what you need.

user2387149
  • 1,219
  • 16
  • 28
  • I thought [#import ensures that a file is only ever included once so that you never have a problem with recursive includes](http://stackoverflow.com/a/439691/4479896). Also, why in the world would you import a `.m`?! – Ky - Dec 18 '15 at 21:59
  • 1
    @BenC.R.Leggiero I meat to import your .h inside the .m ... and importing more than once is not the issue... the issue is when there is a cyclic reference/import making it an infinite loop of importations and impossible to compile. – user2387149 Feb 25 '16 at 17:30
  • I'm saying that cyclic/infinite imports should be impossible with `#import`. – Ky - Feb 25 '16 at 19:35
  • 1
    @BenC.R.Leggiero I think you are right, I just tried to replicate the error and I couldn't. Seems like the compiler got better over these years. I'll do any update if I can replicate the error. – user2387149 Feb 26 '16 at 17:49
7

Be careful if you're using Cordova iOS 4.5.0, an error of this kind may happen

duplicate symbol _OBJC_METACLASS_$_CDVLogger in:
   /Users/toto/Library/Developer/Xcode/DerivedData/imp-hkzujazvkracgugyxunzwnzpeiqx/Build/Intermediates/imp.build/Debug-iphoneos/imp.build/Objects-normal/armv7/CDVLogger.o
   /Users/toto/Library/Developer/Xcode/DerivedData/imp-hkzujazvkracgugyxunzwnzpeiqx/Build/Products/Debug-iphoneos/libCordova.a(CDVLogger.o)

ld: 2 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It can be due to the use of cordova-plugin-console, which is not useful anymore in Cordova iOS 4.5.0 (and breaks the build too!).

To fix it

cordova plugin remove cordova-plugin-console

See reference : https://cordova.apache.org/announcements/2017/09/08/ios-release.html

pom421
  • 1,731
  • 19
  • 38
4

I have faced this problem once before. The reason is that I copied some methods and variables declared in the implementation body from one class to another. So rename these methods and moved these variable to the interface declaration area => solved.

Envil
  • 2,687
  • 1
  • 30
  • 42
3

The only thing that worked for me was to delete my Podfile and then reinstall it.

Make sure you make a copy of all of your original pods before running the following:

$ sudo gem install cocoapods-deintegrate

$ sudo gem install cocoapods-deintegrate cocoapods-clean

$ rm -rf ~/Library/Developer/Xcode/DerivedData

$ pod deintegrate

$ pod clean

$ rm Podfile

$ pod cache clean --all

$ pod init

// next add all the original pods to the new Podfile

$ pod install
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
2

I was seeing the same issue, but with different libraries. The fix was the following:

Target -> Build Phases -> Linked Binary With Libraries

Make sure the libraries included make sense. In my case, my project had libPods*.a (I am using CocoaPods for dependency mgmt) but also a few libraries that were included in my pod shared libraries, and that was causing the duplicates.

josephmisiti
  • 9,862
  • 11
  • 56
  • 72
1

I just fixed this error. I had CocoaPods installing a few frameworks (AWS, SDWebImage, AFNetworking. I manually dragged in 2 frameworks, Facebook and ImageIO. Most of my "duplicate symbol" errors were caught on Facebook classes. I deleted the framework and added it to the Podfile. Must have been an error or duplication in the libraries required by Facebook.

Anna Billstrom
  • 2,482
  • 25
  • 33
1

My problem was... odd. I'm not sure how it happened, but at some point, Xcode decided to include some ancient .m file one more time in its .pbxproj file. The only way I found it was by comparing my changes in git, looking at the version of the code where the build first failed.

Simply removing this line solved my issue: A sample of a git changeset, with one file added and zero removed.

Ky -
  • 30,724
  • 51
  • 192
  • 308
  • 1
    Same. After git merge - there was two different titles with same hash. Just delete one with old hash. How to get it out which is old? It usually one in all list. – Nike Kov Aug 10 '16 at 12:11
0

I had duplicate files in my Xcode. Physically there were one m-file and one h-file. But in project it were doubled causing duplicates in compile sources. After deleting duplicate m and h file problem was solved.

Ruslan Mansurov
  • 1,281
  • 16
  • 23
0

Its because the iPhone simulator got duplicate .h & .m references. I struggled for hours for this bug.

My solution was simple. I copied the project to my pen drive and erased from computer memory.

Opened a new project, copied the storyboard and added the .h &.m files. Some errors fixed by selecting classes again in the storayboard view..

0

I also had duplicate symbols. I just renamed the procedure (app -> app1, app2) and the associated fields app.XXX -> app1.XXX . and it worked !

See : (in a .m file)

AppDelegate* app1;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        app1 = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    }
    return self;
}

(...)

- (int) getLimit
{
    if (app1.product2buyed)
        return MAXID;
    else if (app1.product1buyed)
        return 70;
    else
        return 10;
Tanos
  • 49
  • 8
0

Please check if you have added any framework more then once, remove all framework if added multiple times and then drag and drop again.

Hope this will resolve your problem. Happy Coding.

Tejinder
  • 1,507
  • 19
  • 22
0

YOU MIGHT HAVE SIMILAR PLUGINS INSTALLED.

I am using Cordova, and also had several duplicate symbol errors. I had installed two similar plugins:

  • cordova plugin email composer
  • cordova plugin email

Fixed it by removing "cordova plugin email" using...

cordova plugin remove cordova-plugin-email

After that I ran...

cordova prepare
cordova build ios

Now my xCode build ran like a charm! Woooo Hooo!