I am encountering 'duplicate symbol' errors in Xcode 4.5.1 when I try to build a project after adding my own framework. I verified the framework files for duplicates and there are none. But when I add the framework to a project, it complains with these error. Please suggest..
duplicate symbol _NXArgc in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
duplicate symbol _NXArgv in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
duplicate symbol ___progname in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
duplicate symbol _environ in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
duplicate symbol start in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
ld: 8 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Thanks in advance..
I had the same issue with using two third party framework. I resolved that by removing "all_load" from "Other Linker Flags" in build settings.
Those symbols are in crt.o, the startup code of standard C library. Normally it should be the entry point of executable file to initialize global variables and objects. It will also call your main function.
But for a framework, you should not include it in your binary because framework should not have main.
I believe you have "Link with Standard Library" option as "YES" in your framework's target build setting. This will link crt.o into your framework. And when you link the framework into a project, there will be duplicated symbols.
Please set the option "Link with Standard Library" to NO in your build setting.
Your application has provided an implementation in which there are 8 duplication symbols.
There are a number of ways you might have done this:
You have two modules declaring the same class. Perhaps one is no longer needed?
You are importing any header file in both the files .m and .h :-( Remove from one place.)
You are importing any .m file somewhere. :- (Import .h file instead of .m file)
You have defined and declared any const variable in outside(above) the #interface{} in any of .h file, it might being duplicated. :- (Do it in the .m file.)
Also check, if global variables like constants are defined correctly in .h file in application.
The correct way of defining global variable is to use extern variable in .h file.
Note :This is not an issue with the previous Xcode version. I faced the problem with Xcode 6.3 and it was solved.
If you have this problem only when you run the app in the simulator, it gets solved by deleting the local folder
~/Library/Developer/CoreSimulator
Xcode will restore it after the first build and run.
PLEASE MAKE SURE YOU BACKUP ANY SETTINGS before doing this (especially those related to simulator devices).
Tested on Xcode Version 7.2.1 (7C1002)
Related
I am working on building a Swift library and am hosting it on GitHub.
All was going fine until I added BluetoothKit to the project. I then got an Apple Mach-O Linker Error:
ld: warning: directory not found for option '-F/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/Developer/Library/Frameworks'
ld: /Users/calebklevetertest/Library/Developer/Xcode/DerivedData/Napalm-dblvhbjdwovurocsvzrzaxzkjjyw/Build/Products/Debug-iphonesimulator/Napalm.framework/Napalm compiled with older version of Swift language (2.0) than previous files (3.0) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
From reading the error it appears the issue somehow stems from the fact I am using Swift 3, but I can't figure out how to fix it.
I did convert BluetoothKit to Swift 3 when I added it.
There is one class that uses BluetoothKit and it is called NPFBluetooth.
A couple things to note are 1) Even though the class is public, the compiler gives an error of 'unresolved identifier', 2) The class does not show in the auto-complete and 3) All the other classes work fine.
I ran into the error migrating to swift3. As it turns out Xcode keeps copies of built frameworks and moving to swift3 is apparently not a cue to rebuild those (even after finding out it was built using swift2.... no let's throw a vague error instead...)
The solution is to delete the content of your 'derived data' folder.
Works for frameworks installed with Carthage and cocoapods.....
Go to your build settings and switch the target's settings to ENABLE_BITCODE = YES for now.
It's working for me ;)
I keep getting errors upon building my application on Xcode:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
None of my code is erroring and the errors are weird errors and anything I do does not resolve it. I don't think the code is relevant to the issues because it isn't referenced in the error.
This is a screenshot of the error.
The linker has not been able to find any file in the linking process with the main swift entry point. This can be due to the file not existing at all in your project, or that it exists but has not been included in the compile or link build phases.
In Swift, the main swift entry point is defined in a main.swift module, or (for iOS) in the AppDelegate.swift file there needs to be a #UIApplicationMain declaration. I don't see a Compile main.swift in your log, perhaps its missing or not included in the build phases?
Just in case, check if your AppDelegate app target is selected on the File Inspector.
( Select AppDeletage > Show the Utility > Show the file Inspector > under Target Membership, select your target.)
It happened to me after renaming an existing file.
Some time remove the reference of AppDelegate.swift from the project and add AppDelegate.swift again in project will work.
I have a symbol that is being referenced in an Xcode dynamic library target, but it is not defined there. I NEED this symbol to be undefined. This is because it will be compiled differently in each process that includes it (based upon some compile time defines).
The dynamic library target in Xcode that fails to link because it contains a reference to this symbol (which is not unexpected), but I know that the symbol will be available at run time. I will be compiling this function into each target that the common library is linked to.
I am trying to get the linker to mark this particular symbol for dynamic lookup at run time.
I have been able to get it to link if I specify "-undefined dynamic_lookup" as one of the "Other Linker Flags" in my Xcode project. The problem is that I don't want to go that far. I know that only 1 symbol is supposed to be undefined. I want all the rest of the symbols to generate errors if they are left as undefined (I want to avoid a run time missing symbol error basically).
I found a ld linker option that seems like it should do what I need (from ld man page):
-U symbol_name
Specified that it is ok for symbol_name to have no definition. With -two_levelnamespace, the resulting symbol will be marked dynamic_lookup which means dyld will search all loaded images.
However, I cannot seem to get it to work. Whenever I specify "-U symbolName" or "-UsymbolName" in the "Other Linker Flags" I am still greeted with this linker error:
Undefined symbols for architecture x86_64:
"_symbolName", referenced from: <various object files>
Am I using -U incorrectly perhaps? Is it not really the option I need, or is it just not working like it is supposed too?
Set -Wl,-undefined,dynamic_lookup to OTHER_LDFLAGS.
Link: Xcode clang link: Build Dynamic Framework (or dylib) not embed dependencies
Setting -Wl,-undefined,dynamic_lookup is dangerous, since it disables all undefined warning.
Use -Wl,-U,symbol_namein OTHER_LDFLAGS to disable warnings for a single symbol.
In Xcode:
Go to Project/Select Target
Click Build Settings
Search Other Linker Flags
Enter options
The Problem
Xcode (Version 4.6.1 (4H512)) is complaining a duplicate symbole problem.
duplicate symbol _OBJC_METACLASS_$_PacksStoreHelper in:
/Users/shannoga/Library/Developer/Xcode/DerivedData/English_Club-cyrjamihpabtvtdkvctjwyidupuo/Build/Intermediates/English Club.build/Debug-iphonesimulator/English Club.build/Objects-normal/i386/PacksStoreViewController.o
/Users/shannoga/Library/Developer/Xcode/DerivedData/English_Club-cyrjamihpabtvtdkvctjwyidupuo/Build/Intermediates/English Club.build/Debug-iphonesimulator/English Club.build/Objects-normal/i386/PacksStoreHelper.o
duplicate symbol _OBJC_CLASS_$_PacksStoreHelper in:
/Users/shannoga/Library/Developer/Xcode/DerivedData/English_Club-cyrjamihpabtvtdkvctjwyidupuo/Build/Intermediates/English Club.build/Debug-iphonesimulator/English Club.build/Objects-normal/i386/PacksStoreViewController.o
/Users/shannoga/Library/Developer/Xcode/DerivedData/English_Club-cyrjamihpabtvtdkvctjwyidupuo/Build/Intermediates/English Club.build/Debug-iphonesimulator/English Club.build/Objects-normal/i386/PacksStoreHelper.o
ld: 2 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Usually I go to the Target Build Pases -> Compile Sources and look for the duplicate.
This time as you can see there is no duplication there:
What I tried and some wacky stuff :
Deleting Derived Data.
Removing the project and restarted the mac.
I even tried to delete the so called "duplicate" files and here it got even more wacky - The target successfully builded and there was no warning even that the files were not visible in the file navigator. After the build the app works fine but one of the controllers is not visible.
I Alt+Clicked the import statements of the duplicate files in other files that uses them and it gets me onto a "Zombie" file with all the code inside. But I can not see where xCode get the file from.
What the hell could it be?
I am about to shoot myself. Please save me.
UPDATE: please leave a comment when you have this working without problems on your system. That would confirm that this is a problem in my setup, rather than a bug in XCode.
After upgrading my development system to XCode 4.5.1, and compiling with IOS SDK 6.0, I get the following errors when running on the IOS 4.3 simulator:
dyld: lazy symbol binding failed: Symbol not found: _objc_release
Referenced from: /Users/baraupp/Library/Application Support/iPhone Simulator/4.3.2/Applications/AFD73AB4-7047-468B-A20B-9C941850ED3C/Flyskyhy.app/Flyskyhy
Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation
dyld: Symbol not found: _objc_release
Referenced from: /Users/baraupp/Library/Application Support/iPhone Simulator/4.3.2/Applications/AFD73AB4-7047-468B-A20B-9C941850ED3C/Flyskyhy.app/Flyskyhy
Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation
I have set the deployment target to 4.3, and I use ARC in the project, with some files on -fno-objc-arc. Compiling and linking succeeds without errors, it fails when trying to run on the simulator. It used to work fine before I upgraded.
EDIT:
I found a similar Stackoverflow question that asks almost exactly the same thing, and its answer suggests adding -fobjc-arc to the other linker flags. Unfortunately, that did not solve my problem. EDIT: I checked the flags that are actually used in the link phase, and the -fobjc-arc flag is present while linking, also without me adding -fobjc-arc explicitly.
As suggested by Brad in the comments, I added the library libarclite_iphoneos.a to the project, but that did not help either. I found that library in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc, which is a weird location in my view, but I could not find it anywhere else.
I also did 'nm' on that library, and it does not define the missing _objc_retain symbol either. It does define a _objc_retain$non_lazy_ptr, though, not sure what that means.
EDIT: I found out that the library gets ignored:
ld: warning: ignoring file libarclite_iphoneos.a, missing required architecture i386 in file libarclite_iphoneos.a
So obviously, it is not the correct file. But I cannot find the same file anywhere else on my system (I have searched with 'find').
Any ideas?
The problem was triggered by a +initialize method in a class category. Apparently, the Apple linker does not handle that case correctly.
After searching the web a lot, I saw that other people also have had issues with +load and +initialize methods, ARC and 4.3 compatibility.
In my case, I initialized a static variable in a category as such:
#implementation NSDictionary (FormAccess)
static NSRegularExpression *pattern;
+ (void) initialize
{
pattern = [[NSRegularExpression alloc] initWithPattern:#"(\\w+)|\\[([0-9]+)\\]" options:0 error:nil];
}
...
#end
The problem disappeared when I replaced that with an explicit initialization the first time the variable was used. I did not need to add any linker flags.
Note that if you have a non-ARC project that uses some ARC files, you still need to add the "-fobjc-arc" flag to "Other Linker Flags", to avoid the same error message.