The app I've been working on uses an external library, pdlib, which has it's own externals (.c files) which I've been importing via the bridging header #import "Uzi.c" and calling in my main Swift file via Uzi.c's setup function Uzi_setup() in my ViewController class. I've had no problem with this until after updating to new public Xcode 8 a few days ago (I had no problem with Xcode 8 Beta 1 over the Summer).
Here are the 7 errors I get, listed under a single "Mach-O Linker Error" umbrella:
Undefined symbols for architecture x86_64:
"_Uzi_bang", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_class", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_float", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_new", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_pause", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_resume", referenced from:
_Uzi_setup in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Those undefined symbols are 6 functions and a class declare from Uzi.c. Here's a link to the whole c file: https://github.com/electrickery/pd-miXedSon/blob/master/hammer/Uzi.c
I've tried every solution I've found online for dealing with similar problems, with no solution yet... I tried changing the "Architecture" and "Valid Architecture" settings to only armv7 and armv7s (no arm64) and changed "Build Active Architecture Only" to "No". These step seem to help others in similar situations, but they didn't work for me (and taking away arm64 causes additional errors to appear).
XCode 8 is pretty recent (the public version was released Sept. 13), so there are virtually no other questions about this upgrade causing a similar problem.
Any help would be greatly appreciated!
Solved by #danomatika on GitHub: https://github.com/libpd/libpd/issues/149
"You generally shouldn't include/import an implementation file aka .c, .cpp, .m, etc. This is what is causing the duplicate symbol issue.
This is what the "forward function declaration" in the header file is for: to tell the compiler that a function exists and what data it takes/returns. The compiler then assumes the actual implementation of the function exists in an implementation file. If it can't be found, then you get an "undefined symbol error." If you somehow end up declaring the function twice, aka include both a header with the forward declaration and the implemetaton of the function itself in the .c file, then you get a "duplicate symbol error."
This is all lower-level stuff that is only really an issue since Pd externals are designed around being dynamic libraries, so are not built or provided with headers which include the function declarations. This is why you have to do a little extra work and do it yourself.
Their are two easy fixes for this, both of which involve declaring the required function you want to call from the .c file in a header file.
Simply declare the function in the bridging header:
void uzi_setup();
Create a header, say Externals.h, and declare all of the externals stuff there:
// forward declare setup functions only found in .c implementations
void uzi_setup();
// convenience wrapper function
void externals_setup() {
uzi_setup();
}
Then import the file in your bridging header:
#import "Externals.h"
And in swift, you can now do:
externals_setup()
I'm including the Layar SDK framework into my app (version 8.0) and everything works fine on a device.
However, I can't run the app on a simulator anymore - I don't mind Layar not working (there's no camera after all!) but I do need it to compile for continual integration, automated tests etc (not to mention developing on the train top/from work!)
The linker gives me these errors :
ld: warning: ignoring file /Users/username/Documents/appname/libs/MPOAuth/libMPOAuthMobile.a, missing required architecture i386 in file /Users/username/Documents/appname/libs/MPOAuth/libMPOAuthMobile.a (2 slices)
ld: warning: ignoring file local/LayarSDK/LayarSDK.framework/LayarSDK, missing required architecture i386 in file local/LayarSDK/LayarSDK.framework/LayarSDK (2 slices)
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_LayarSDK", referenced from:
objc-class-ref in MYAppDelegate.o
ld: symbol(s) not found for architecture i386
Checking, the LayarSDK doesn't contain i386, it only contains armv7 and armv7s.
My solution is pretty clumsy - if anyone has a better idea, please let me know!
I compile this file (LayarSimulatorStub.m) into my app :
#if TARGET_IPHONE_SIMULATOR
#import <Foundation/Foundation.h>
#interface LayarSDK : NSObject
#end
#implementation LayarSDK
+ (id)layarSDKWithConsumerKey:(id)a andConsumerSecret:(id)b andDelegate:(id)c { return nil; }
- (id)init { return nil; }
- (id)initWithConsumerKey:(id)a andConsumerSecret:(id)b andDelegate:(id)c { return nil; }
#end
#endif
Now, there is an i386 symbol LayarSDK. It just returns nil from all it's constructors. The app now compiles with Layar disabled.
The conditional compilation means that it's not present for the device architectures so there are no linker errors.
When i try tests like
#interface My_Tests : XCTestCase
- (void)testExample {
XCTAssertTrue(#YES, #"has to be passed");
}
Everything is working fine. However when i try such pattern:
#import "NSString+Additions.h"
//...
- (void)testNameValidation {
NSString *string = #"Harry";
XCTAssertTrue([string stringIsValid], #"Name validation error");
}
I get:
file:///Users/username/project/ProjectTests/ProjectTest.m: test failure:
-[Project_test testNameValidation] failed: (([string stringIsValid]) is true)
failed: throwing "-[__NSCFConstantString stringIsValid]: unrecognized selector
sent to instance 0x2f58ae8" - Name validation error
I can also just do something like this:
#import "MyViewController.h"
//...
- (void)testSomething {
MyViewController *a = [[MyViewController alloc] init];
XCTAssertTrue(#YES, #"Impossible!");
}
I get 2 errors (first and last line):
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_MyViewController", referenced from:
objc-class-ref in MyTest.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can someone explain me what am I doing wrong..? I can't do anything with my classes. It may be worth adding that i'm trying to test my custom static library and files included in it. I'm using CocoaPods and I've set environment basing on Kiwi description (only to be able to use CocoaPods files in my tests, I was also wondering whether to use Kiwi or XCTests).
PS. This is my first try with unit tests of any type, so please forgive eventual noobish question ;)
The unit tests aren't linked against the static library.
Add the library to the "Link Binary with Libraries" section of the build phases for the test target.
I cannot compile my project for the device or simulator anymore. I get 13 Apple Mach-O-Linker errors. It all started after I failed attempt to use sharekit. Here is the log from the error:
ld: warning: directory not found for option '-F/Users/bbrandy95/Documents/Broken Brandsonic Web Projects/Brandsonic Web mobile/../../Downloads/0.2.1gm1/iphoneos4.0/System/Library/Frameworks'
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_NSURLRequest", referenced from:
objc-class-ref in Brandsonic_Web_mobileAppDelegate.o
objc-class-ref in Brandsonic_Web_mobileViewController.o
"_OBJC_CLASS_$_NSAutoreleasePool", referenced from:
objc-class-ref in main.o
"_objc_msgSendSuper2", referenced from:
-[Brandsonic_Web_mobileAppDelegate dealloc] in Brandsonic_Web_mobileAppDelegate.o
-[Brandsonic_Web_mobileViewController didReceiveMemoryWarning] in Brandsonic_Web_mobileViewController.o
-[Brandsonic_Web_mobileViewController dealloc] in Brandsonic_Web_mobileViewController.o
"_objc_setProperty", referenced from:
-[Brandsonic_Web_mobileAppDelegate setWindow:] in Brandsonic_Web_mobileAppDelegate.o
-[Brandsonic_Web_mobileAppDelegate setViewController:] in Brandsonic_Web_mobileAppDelegate.o
"__objc_empty_vtable", referenced from:
_OBJC_CLASS_$_Brandsonic_Web_mobileAppDelegate in Brandsonic_Web_mobileAppDelegate.o
_OBJC_METACLASS_$_Brandsonic_Web_mobileAppDelegate in Brandsonic_Web_mobileAppDelegate.o
_OBJC_CLASS_$_Brandsonic_Web_mobileViewController in Brandsonic_Web_mobileViewController.o
_OBJC_METACLASS_$_Brandsonic_Web_mobileViewController in Brandsonic_Web_mobileViewController.o
_OBJC_METACLASS_$_SecondView in SecondView.o
_OBJC_CLASS_$_SecondView in SecondView.o
"_objc_msgSend", referenced from:
_main in main.o
-[Brandsonic_Web_mobileAppDelegate application:didFinishLaunchingWithOptions:] in Brandsonic_Web_mobileAppDelegate.o
-[Brandsonic_Web_mobileAppDelegate dealloc] in Brandsonic_Web_mobileAppDelegate.o
-[Brandsonic_Web_mobileAppDelegate GOOGLE] in Brandsonic_Web_mobileAppDelegate.o
-[Brandsonic_Web_mobileAppDelegate YOUTUBE] in Brandsonic_Web_mobileAppDelegate.o
-[Brandsonic_Web_mobileAppDelegate WIKI] in Brandsonic_Web_mobileAppDelegate.o
-[Brandsonic_Web_mobileViewController webView:shouldStartLoadWithRequest:navigationType:] in Brandsonic_Web_mobileViewController.o
...
"__objc_empty_cache", referenced from:
_OBJC_CLASS_$_Brandsonic_Web_mobileAppDelegate in Brandsonic_Web_mobileAppDelegate.o
_OBJC_METACLASS_$_Brandsonic_Web_mobileAppDelegate in Brandsonic_Web_mobileAppDelegate.o
_OBJC_CLASS_$_Brandsonic_Web_mobileViewController in Brandsonic_Web_mobileViewController.o
_OBJC_METACLASS_$_Brandsonic_Web_mobileViewController in Brandsonic_Web_mobileViewController.o
_OBJC_METACLASS_$_SecondView in SecondView.o
_OBJC_CLASS_$_SecondView in SecondView.o
"_OBJC_CLASS_$_NSObject", referenced from:
_OBJC_CLASS_$_Brandsonic_Web_mobileAppDelegate in Brandsonic_Web_mobileAppDelegate.o
"___CFConstantStringClassReference", referenced from:
CFString in Brandsonic_Web_mobileAppDelegate.o
CFString in Brandsonic_Web_mobileAppDelegate.o
CFString in Brandsonic_Web_mobileAppDelegate.o
CFString in Brandsonic_Web_mobileViewController.o
CFString in Brandsonic_Web_mobileViewController.o
CFString in Brandsonic_Web_mobileViewController.o
CFString in Brandsonic_Web_mobileViewController.o
...
"_OBJC_CLASS_$_NSKeyedUnarchiver", referenced from:
objc-class-ref in Brandsonic_Web_mobileViewController.o
"_OBJC_CLASS_$_NSUserDefaults", referenced from:
objc-class-ref in Brandsonic_Web_mobileViewController.o
"_OBJC_CLASS_$_NSURL", referenced from:
objc-class-ref in Brandsonic_Web_mobileAppDelegate.o
objc-class-ref in Brandsonic_Web_mobileViewController.o
"_OBJC_METACLASS_$_NSObject", referenced from:
_OBJC_METACLASS_$_Brandsonic_Web_mobileAppDelegate in Brandsonic_Web_mobileAppDelegate.o
_OBJC_METACLASS_$_Brandsonic_Web_mobileViewController in Brandsonic_Web_mobileViewController.o
_OBJC_METACLASS_$_SecondView in SecondView.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
'
How do I fix this? Please help.
For every one with an similar error.
If that happens you normally can remove the "Path" under Point
target->Build Settings->Library Search Paths
This error can occur when a framework is added to a project more than once.
You can fix this by removing the duplicate. To find it, select the framework in the Xcode project navigator and choose Show in Finder. Then clean and build your project.
This can also be caused if you're missing framework header files or a reference to them.
In that case, you should trying removing the SDK or framework and adding it again.
Good luck.
If you installed dependencies using CocoaPods, make sure you open your XCode project by clicking on your .xcworkspace file, and not the .xcodeproj file.
It seems like the project file may have been corrupted somehow.
The most sure way to fix this is to create a new project, and move your files and old info.plist over on top of it.
The next most likely way to fix this is to create a new target in your current project, and see if that will compile (if you have any special flags from the old target you'll want to copy them).
Also you could try compiling for Release vs. Build and if one of them works look at all of the compiler options and see what is different.
If you added a header search path for Sharekit, perhaps try clearing out the whole header search path and see if that fixes things. Also make sure your project is still including frameworks that a brand new project includes (UIKit and NSFoundation, possibly others).
Add the .m file to compile source page.
steps:-
clicking on he project in the navigation menu
select the target
select build phases
Select the + button and add the file in compile sources.
Hope that helps anyone with this problem
The problems are the spaces in your path:
xcode uses the following switch for the linker:
-F/Users/bbrandy95/Documents/Broken Brandsonic Web Projects/Brandsonic Web mobile/../../Downloads/0.2.1gm1/iphoneos4.0/System/Library/Frameworks
and since it is not quoted it won't work. ( It is looking for the folder "/Users/bbrandy95/Documents/Broken"
You should rename the directories, or look through the project settings and add quotes to the directories. (But this might be tricky to find)
I too had the same problem with 45 same kind errors, when I add the libxml2.dylib into my project the errors disappeared.
In some cases your library Search Path is empty.Because there are many Apple-mac-o linker errors.
See my answer also at.
Apple Mach-O Linker Error using Core Data classes in OCUnit
I had this issue, now for my circumstances selecting a more recent iOS version as the deployment target rectified this for me. My project was set to deploy to iOS 5 by default and changing this to 7 (the most recent) did the trick.
For anyone new to iOS development this can be done by clicking on your XCode project file in the navigator > deployment info > deployment target and selecting the appropriate version from the drop down menu.
I'm sceptical that this will solve some of the issues that others are having but there may be a few people out there in the same boat as me.
It's because the project inserted the core data's xcdatamodeld file in compile sources. Select your project -> Build Phases -> Compile Sources and delete projectName.xcdatamodeld file.
And also check if you have imported .m file instead of .h file, it also gives the same linker error. Check all the #import codes.
And check if you have added core data frame work in library and imported core data .h file. Check for creation of NSManagedObject and import it's file.
Just try it and reply me if still any error.
I had the same problem,
I just simply set the Build Option -> Enable Bitcode to NO
I faced this problem with my self developed cocoapod.
Error was: Apple Mach-O Linker errror
It turned out, that I had defined a protocol and implemented a protocol extension. One method of the protocol extension was public, but the protocol itself was not. And this caused the Apple Mach-O Linker error.
Example:
protocol MyProtocol { var field: String { get} }
extension MyProtocol { public func giveMeSomething() -> String }
public class MyClass: MyProtocol {}
In the description the error mentioned MyClass referenced from MyProtocol -> MyProtocol referenced from giveMeSomething()...
So, the solution was to make Myprotocol also public
Hope that helps someone.
I want to use the http://getsharekit.com framework for future iOS projects. Hence I started testing out the framework.
But I already get the following error:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_SHKItem", referenced from:
objc-class-ref in ShareKitTestAppDelegate.o
"_OBJC_CLASS_$_SHKActionSheet", referenced from:
objc-class-ref in ShareKitTestAppDelegate.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
Often, as far as I know, these problems arise if header files are wrongly imported. But I don't see any error here in the following code where the problem above occurs:
#import "ShareKitTestAppDelegate.h"
#import "SHK.h"
#import "SHKItem.h"
#import "SHKActionSheet.h"
- (IBAction) letshare:(id)sender
{
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:#"http://getsharekit.com"];
SHKItem *item = [SHKItem URL:url title:#"ShareKit is Awesome!"];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[self.window addSubview:actionSheet];
}
I also included the ShareKit Headers Folder into HeaderSearchPath Build-Options, because of searching for all the headers.
But I don't see any error here or anything missed.
Can somebody help me?
With best regards,
Andreas
I had a similar problem with the following linker error:
Undefined symbols for architecture i386: "_OBJC_CLASS_$_SHK"
I resolved it by adding SHK.m to compiled sources under Project settings->Target->Build Phases. Not sure why SHK.m was not in the compiled sources list, and it was working previous to duplicating the Target. After the duplication I couldn't link any of the targets.
Adding SHKItem.m or SHK.m to compiled sources might help you if they aren't there already.
Read this http://getsharekit.com/install/.
Have you added the frameworks?