iOS import custom framework into project - ios

I've developped a framework which I want to use in my projects. Everything went right until I tried to build my project. Here the error description :
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_ClassInFramework", referenced from:
objc-class-ref in ClassInMyProject.o
ld: symbol(s) not found for architecture arm64
My Architectures build settings are :
$(ARCHS_STANDARD)
and arm64 armv7 armv7s for valid arch
(same settings in my project and my framework, there are all default settings)
I can import myframework and build with no issue, but I get that error when I tried to use a class.
I'm on XCode 8.2.1, my Framework is a Cococa touch Framework, written in Objective-C, my project is written in Swift 3.0
I imported my framework by copying the output from Products and added it in Linked Frameworks and Libraries in my project
I've tried several different settings but none of them work.

You should remove the project folder from Xcode Drived Date and restart your Xcode then clean your project and run it.

I didn't solve my issue but I've managed to do something similar.
Instead of creating a Cocoa touch framework I created a Cocoa Touch static library and it worked.
I build my library,
I get the products (*.h and .a files), copy them in my project,
I add the lib.a in Linked Frameworks and libraries,
I create the Bridging Header and #import my "customlib.h",
Magic ! It works I can use my class.

Related

Wrapping static library in Cocoa Touch Framework

I have a fat static library with 2 architecture slices (armv7, arm64).
I'm trying to make it work with swift and wrap it into Cocoa Touch Framework.
What I do:
Create Cocoa Touch Framework project
Drag .a static library with headers
Set OTHER_LDFLAGS to -all_load
Set ONLY_ACTIVE_ARCH to NO
Set VALID_ARCHS and ARCHS to armv7 and arm64
Build with Release build configuration
Grab .framework file from DerivedData/../../Products/
When I put this .framework into my swift project, add to Embedded Binaries section in my targets general settings, import framework and use one of its classes, I'm getting undefined symbols for architecture arm64 or undefined symbols for architecture armv7.
EDIT:
Not sure if it helps but I've noticed that size of static library is about 34MB but size of generated .framework is about 12MB.
EDIT 2:
I ran nm -arch arm64 -g myLibraryName on both static library and generated dynamic library. The dynamic library doesn't contain all symbols that static library has. Seems like XCode build process strips lots of them.
I think you have also forgotten to add :
Project->Target->Build Phases->Link Binary With Libraries:
add + the: libz.dylib or libz.tbd
(Since Xcode 7 the *.dylib files are now *.tbd files)
Be sure to also clean the folder: /User/yourname/Library/Developer/XCode/DerivedData
P.S: If you want you should also be able to add the libz.tbd from "Other Linker Flags" in the Build Settings by adding the argument -lz.

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_CMMotionManager", referenced from: objc-class-ref in GooglePlus(GPPSpamSignal.o)

Hello I have a project that some one has developed. It has G+, FB integration. When I get the project and try to run it, it gives me this error. How I can solve this? Please help me.
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_CMMotionManager", referenced from:
objc-class-ref in GooglePlus(GPPSpamSignal.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Thanks
Undefined symbols means usually that you are missing an import statement.
Looks like you are using
CMMotionManager is part of CoreMotion, so you might need to :
#import <CoreMotion/CoreMotion.h>
And verify that you have added CoreMotion to your project
As CMMotionManager is part of CoreMotion framework, simply include the framework in your build in Xcode in "target"'s Build Phases: "link with": add "+" "CoreMotion.framework"
I managed to invoke this unholy error by simply adding the .h and .m files to the project.
I fixed this by removing them, and then right-clicking on the project, clicking New File, and choosing a new iOS Cocoa Touch class.
After that, I copied the relevant code into the respective .h and .m files. Doing it this way properly links the files
CMMotionManager is part of CoreMotion.framework.
In Xcode 11.3, TARGETS > Frameworks, Libraries, and Embedded Content > click the add button '+', add CoreMotion.framework.
The picture is in the below.
It appears that you are using GooglePlus SDK and the SDK is not supporting arm64 architecture. You need an updated SDK that supports arm64 architecture. Make sure you have latest copy.

Xcode - Created an iOS framework but can't use it in a project

I've created an iOS framework with this tutorial: http://www.raywenderlich.com/65964/create-a-framework-for-ios#comments
When I add it to a completely new project, I can import my public header and I can build it successfully. The problem comes when I try to create an instance of an object from the framework; when building it, fails with 40 errors:
All errors are displayed like this:
Apple Mach-O Linker Error "_OBJC_CLASS_$_AVPlayerItem < this is an example.
At the bottom it shows this message > Symbol(s) not found for architecture arm64
At first I thought the problem was that the framework I created wasn't supporting arm64. I executed the following line in Terminal to check which architectures were supported by my framework:
xcrun lipo -info MyFramework
The output is > Architectures in the fat file: MyFramework are: armv7 i385 x86_64 arm64
I'm using Xcode 6.4.
Thank you.
UPDATE: Here are some images of the error list:
Thanks!
I could be wrong but I think that in your MyFramework project you used several iOS frameworks like AVFoundation and also C++ standard library (libstdc++.6.dylib). In your fat library you don't have them. You need to add this dependencies manually to that project.
Another good tutorial about creating iOS Framework is iOS Framework Tutorial
Go to Build Phases in your Xcode settings. Select Target Dependencies. Add your framework Target (with Tests target). And Clean the project and delete your all derivedData and Run project. Very Easy.

Xcode 6 linker error - Undefined symbols for architecture armv7

After upgrading to Xcode 6 beta 7 (and now still with Xcode 6 GM) I am unable to link my Swift app. I receive errors such as:
Undefined symbols for architecture armv7:
"_swift_stdlib_compareNSStringDeterministicUnicodeCollation", referenced from:
...
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have seen the other SO posts that recommend deleting the Derived Data folder and/or using the Clean Build Folder option to get past this error, but that solution didn't help at all in my case. Nothing has changed about my code or the CocoaPods I'm using since Xcode 6 beta 5 which is the last time it worked.
Any ideas?
EDIT:
A full posting of the error log:
Undefined symbols for architecture arm64:
"_swift_stdlib_compareNSStringDeterministicUnicodeCollation", referenced from:
TFC12MyProject21BarcodeViewController13captureOutputfS0_FTGSQCSo15AVCaptureOutput_24didOutputMetadataObjectsGSQGSaPSs9AnyObject___14fromConnectionGSQCSo19AVCaptureConnection__T_ in BarcodeViewController.o
"__TFSs21_arrayConditionalCastU___FGSaQ__GSqGSaQ0_", referenced from:
TFC12MyProject27SessionsTableViewController17viewWillDisappearfS0_FSbT_ in SessionsTableViewController.o
"__TFSs15_arrayForceCastU___FGSaQ__GSaQ0", referenced from:
__TFC12MyProject7RestApi12tokenMappingfS0_FT_CSo15RKEntityMapping in RestApi.o
__TFC12MyProject28AttendeesTableViewControllerg24fetchedResultsControllerCSo26NSFetchedResultsController in AttendeesTableViewController.o
__TFC12MyProject27SessionsTableViewControllerg24fetchedResultsControllerCSo26NSFetchedResultsController in SessionsTableViewController.o
__TFC12MyProject21BarcodeViewController13startScanningfS0_FT_Sb in BarcodeViewController.o
"__TFSs26_forceBridgeFromObjectiveCU__FTPSs9AnyObject_MQ__Q_", referenced from:
__TFC12MyProject7RestApi12resetRestKitfS0_FT_T_ in RestApi.o
__TFC12MyProject16BluetoothManager17_startAdvertisingfS0_FT_T_ in BluetoothManager.o
__TFC12MyProject19LoginViewController32registerForKeyboardNotificationsfS0_FT_T_ in LoginViewController.o
__TFC12MyProject19LoginViewController35deregisterFromKeyboardNotificationsfS0_FT_T_ in LoginViewController.o
__TFC12MyProject19LoginViewController16callProcessLoginfS0_FT_T_ in LoginViewController.o
__TFC12MyProject21CheckinViewController16enableBeaconModefS0_FT_T_ in CheckinViewController.o
__TFC12MyProject21BarcodeViewController13startScanningfS0_FT_Sb in BarcodeViewController.o
...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What's happening here has nothing to do with your Derived Data location.
When a swift application is built, it goes through several steps:
Write auxiliary files
Create product structure
Compile swift source for each architecture
Copy resource rules plist
Copy application bridging header
Link against swift runtime libraries for each architecture
Copy application swift module for each architecture
Create the application binary
Copy resources build phase
Copy the swift standard libraries into the application
Package it up
Sign it
Whew! That's a lot. Your build is failing when linking against the swift runtime libraries. They live in Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos inside the Xcode developer directory. Specifically, the library that is not being correctly linked is libswiftCore.dylib. If you use nm on that library, you can see it defines your first missing symbol:
quellish% nm /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCore.dylib | grep compareNSStringDeterministicUnicodeCollation
00197c8c T _swift_stdlib_compareNSStringDeterministicUnicodeCollation
000000000018352c T _swift_stdlib_compareNSStringDeterministicUnicodeCollation
You can also use lipo to see what architectures are in the file:
quellish% xcrun lipo -info /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCore.dylib
Architectures in the fat file: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCore.dylib are: armv7 arm64
It contains armv7 and arm64. It's not the library architecture that's the problem.
Linking against the swift standard library is not working. It's possible that source control or migrating Xcode versions has caused your project file to drop part of the linking step, or it's simply not able to find the libraries it needs to link against. Xcode project files are complex and use a lot of references - it's possible that a merge, etc. caused a critical reference to be come dissociated from the linking step. Without a full build log and a look at your machine it may not be possible to tell.
This library, as you might guess, has nothing to do with the project's derived data location.
The best way to move forward would unfortunately be to recreate the project file. Comparing the build log of the broken project to a swift project that does build correctly may provide some insights, but it may also be a waste of time - something fixable may be the problem, but more likely not.
I would encourage you to file a bug and include the troublesome project file with it.
I have solved my issue by deleting all the data in the ~/Library/Developer/Xcode/DerivedData folder. I read about that in another thread, but ignored it thinking a clean included that process!
I have Updated on Yosemite, Xcode 6.1.
I have updated gem xcodeproj (0.19.4) and cocoapods (0.34.4).
I have resolve my conflict by :
Clearing the Library/Developer/Xcode/DerivedData folder
replace in Target -> Build Settings -> Linking -> Other Linker Flags : $(OTHER_LDFLAGS)
Check in Target -> Build Phases -> Copy Pods Resources : "${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh"
1) I face the same problem but just clear the applications from derived data from User/Library/Developer/Xcode/DerivedData and I am able to run the code.
2) In your case may be, it will run by removing armv7 architecture from build settings. And make sure your compiler is Default Compiler in Build Settings.
Thanks I hope this helpful to you and everyone.
This seems to be caused (for most) by linking a third-party library that does not support the requested architecture.
I had somewhat similar problem (a linker error from Apple's framework). As it turned out, the problem was that I was missing the library LocalAuthentication.framework. I am wondering if maybe you need to delete the Foundation.framework from the Build Phase tab (in the Link Libraries section), and then re-add it? Maybe that will solve the problem?
'Upgraded' to xcode 6 and swift app wouldn't build for simulator yet would build fine on an iPad - Linker error, undefined symbols for i386 for the simulator.
Clearing the Library/Developer/Xcode/DerivedData folder worked for me.
There appears to be a bug in Xcode 6.0.1 that is causing the linker to drop dependencies in existing project files. I have had this same problem across several different projects, new and old, since the 6.0.1 update.
The easy 'fix' is to just trash your entire 'Derrived Data' and all build files (i.e. manually clean the project) and then rebuild after a fresh Xcode restart. Magically, the linker now finds all the missing architectures/symbols.
NOTE: I have had several incompatible v-table crashes caused by this same bug. The C++ linker appears to be generating incomplete linkages, causing absurd errors where there are no real errors to be found. Again, just rebuild from a clean state and .. ta da.. save yourself a LOT of headache and wasted time tracking down a non-issue.
I solved this issue after trying all that was suggested here with no luck.
Like someone said earlier, it's a SourceControl issue.
One of my project files (the one referenced in the error message) was missing from the project browser. However, XCode still had a reference to it (I was going to the class definition when I was selecting "jump to definition" from Xcode GUI).
As a matter of fact, the project.pbxproj was not listing it. This was probably a Git Issue. In any event, I just recreated the file in the same directory it has been recreated and voila.
I am a filly when it comes to iOS Objective C, though I have been coding in several other languages for many years. So I am stabbing around in the dark most of the time with Objective C.
I started having this error, "Undefined symbols for architecture armv7", directly after declaring some "global" variables in my .h file like so:
extern NSString *globalNotes;
extern NSString *globalUserCountry;
I was then referring to these variables from the .m file like so:
globalNotes= #"Error (Marker 1010)";
globalUserCountry= #"No result";
THE FIX - To correct this, I changed them to object properties like so:
#property(nonatomic, strong, readwrite) NSString *globalNotes;
#property(nonatomic, strong, readwrite) NSString *globalUserCountry;
And referred to them like so:
self.globalNotes= #"Error (Marker 1010)";
self.globalUserCountry= #"No result";
That seemed to fix my problem.

Cocoa Static Library with ZXing error

My project uses some Cocoa static libraries, one of which is a Zxing Project. I am getting a lot of errors while trying to incorporate this project. Weirdly enough, I was able to create a demo with Zxing in a separate project, without any errors. My main project builds and runs ok, as long as I do not include the Cocoa static library for Zxing.
So the question is, how do I include the ZXing static library to my Cocoa project? How do I configure library (e.g. how do I set the Header Search Paths~~).
Thanks.
Some detail about my project
The Structure
EnjoyMobile
-CustomStaticLibrary.xcodeproj
-ZXingWidegt.xcodeproj
Header search Paths in my -CustomStaticLibrary Target
./zxing/iphone/ZXingWidget/Classes
./zxing/cpp/core/src
The error
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_QRCodeReader", referenced from:
objc-class-ref in libCustomerLibrary.a(CustomerViewController.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Zxing is kind of a painfull integration, also in the newer versions of Xcode Apple added more error checks. I would suggest you to use cococapods for a better integration or this ObjectiveC wrapper here
It's not seeing some of the lib classes. Double check the steps in the README, particularly step 2. If it still fails, post the link command that fails.

Resources