Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-ObjC linker flag causes duplicate symbol errors

I am required to include the -ObjC flag in "Other Linker Flags" in Xcode to use a 3rd-party component. However, once I add this flag, I get a slew of errors that look like this:

    duplicate symbol _OBJC_IVAR_$_GAI.defaultTracker_ in:
        /MyApp/GoogleAnalytics/libGoogleAnalytics.a(GAI.o)
        /MyApp/GoogleAnalytics/libGoogleAnalytics_debug.a(GAI.o)
    duplicate symbol _OBJC_IVAR_$_GAI.dispatcher_ in:
        /MyApp/GoogleAnalytics/libGoogleAnalytics.a(GAI.o)
        /MyApp/GoogleAnalytics/libGoogleAnalytics_debug.a(GAI.o)
...
    duplicate symbol _OBJC_CLASS_$_GAIDispatcher in:
        /MyApp/GoogleAnalytics/libGoogleAnalytics.a(GAIDispatcher.o)
        /MyApp/GoogleAnalytics/libGoogleAnalytics_debug.a(GAIDispatcher.o)
    duplicate symbol _OBJC_METACLASS_$_GAIDispatcher in:
        /MyApp/GoogleAnalytics/libGoogleAnalytics.a(GAIDispatcher.o)
        /MyApp/GoogleAnalytics/libGoogleAnalytics_debug.a(GAIDispatcher.o)
    ld: 212 duplicate symbols for architecture armv7s

Again, this all disappears if I don't use the -ObjC flag. It appears to have something to do with the Google Analytics library. How do I get around this?

like image 627
soleil Avatar asked Jul 29 '13 18:07

soleil


1 Answers

Edit the release and debug configurations of your build target. Include the debug version of the library in the debug config, and the non-debug version for the release target. Don't include both in the same config--this is why you're getting duplicate symbols.

Remove the two libraries from your build targets, eg:

remove libraries from build targets

Then search for "other linker flags" in your build target's settings and add "-lGoogleAnalytics_debug" for the Debug config and "-lGoogleAnalytics" for the Release config, eg:

set linker flags for debug and release configs

like image 172
Nicholas Hart Avatar answered Sep 28 '22 22:09

Nicholas Hart