How to link to another library in Xcode? - xcode

I created a command line application. Then I realized it would be handy to be able to use code in other projects, so I added a new target - a cocoa library.
It seems to compile and a .a file is generated.
Now in another project I want to use this library. So first I added the first project to this new project as a reference.
In build settings I set "Always search user paths" to YES, then keyed in the path to the above project in user header paths.
In build phases, "Link Binary with libraries" , I added the .a file.
Now in my new project code sense seems to work. But when I try to build, I get an error : ndefined symbols for architecture x86_64:
"_OBJC_CLASS_$_RIImageSplitter", referenced from:
objc-class-ref in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What did I do wrong? :S I am a beginner.

Didn't add file to compile sources of target. =S

Check this:
Did you drag the static library to your project navigator?
Did you add in Target/Build Phases/ Target Dependencies?
Did you add the Header Search Path for the headers of the static library?
Good Luck!

Related

xcode 10.1 Undefined symbols for architecture arm64

I already gone so many SO threads with similar issue but none of them seems to resolve my error.
In our project we have multiple "TARGETS". Only one of the target - the very first target created ever - is archiving properly. When I try to archive other target we encounter this error
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_DynamicEventData", referenced from:
objc-class-ref in DataManager.o
objc-class-ref in DataReader.o
"_OBJC_CLASS_$_DynamicDataService", referenced from:
objc-class-ref in DataManager.o
"_OBJC_CLASS_$_DynamicDataConfig", referenced from:
objc-class-ref in DataManager.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I did compare the Build Setting of the working target to the other targets but all of them are equal. I checked the header files and they exists in our project directory. I tried to manually add the header files' path to Header Search Paths but same result still getting the error.
Any idea? I really need to resolve this to export an ipa file.
Thanks!
I scan manually check the Build Phases > Link Binary With Libraries of the working target vs the defected targets. I found a one framework/library that was only added to the working target the said framework isn't manage by pod that may explain why the other target doesn't have it. I think it was added manually in the project.
I add the said framework to all targets and now I can build without the said error.
Thanks!
I encountered the same problem and the solution I found is so simple (man....).
Search in the project for the classes that are mentioned in the error.
Go to the "File Inspector" and simply check V for the rest of the targets in the "Targets Membership".
That's it! It took me Two Hours (wasted time) to find out.
Hope my solution will save time for anyone with similar problem.

linker command failed in react native app, using react-native-firebase

I developed a react native app using react-native-firebase library.
I want to set my app icon, so I used this library:npm install -g yo generator-rn-toolbox from here.
When I try to build the project I receive this error:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_RCTSRWebSocket", referenced from:
objc-class-ref in libReact.a(RCTInspectorPackagerConnection.o)
"_OBJC_CLASS_$_RCTReconnectingWebSocket", referenced from:
objc-class-ref in libReact.a(RCTPackagerConnection.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
How do I fix this ?
I fixed it by manually adding the RCTWebsocket library:
find the RCTWebsocket project: open -R node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj
Drag it into xcode under your projects Libraries folder
on your project, select your project target, then goto "Build phases" --> "Link Binaries With Libraries" --> "+"
Search for libRCTWebSocket.a and add it
your project should build now. If libRCTWebSocket.a in step 4 is not there, try to build the project first.
I had the similar issue for iOS 12, XCode 10.
For those that may help (and avoid losing days like me..),
i had to add the libRCTWebSocket.a and the libfishhook.a binaries in the YourProject -> Targets -> YourProject -> Link Binary With Libraries list
I was able to build the app by placing libRCTWebSocket.a before libReact.

Unity project. Undefined symbols for architecture armv7

I make a build for iPhone for the first time and got a problem.
I already checked a lot of posts and didnt find answer.
When i make a build on device a get:
Undefined symbols for architecture armv7:
"RegisterAllStrippedInternalCalls()", referenced from:
RegisterAllInternalCalls() in libiPhone-lib.a(MonoICallRegistration.o)
"RegisterAllClasses()", referenced from:
InitializeEngineNoGraphics() in libiPhone-lib.a(SaveAndLoadHelper.o)
"RegisterMonoModules()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
On simulator ok.
libiPhone-lib.a added to link libraries.
Can somebody tell what it is? Please
Your unity version is not compatible, just download the latest version of unity which I believe is 4.3.1 and try recompiling. Here is the link if you need it. http://unity3d.com/unity/download/download-mac
The new version is compatible with armv7.
ok if anyone else is experiencing the same problem here's a way out:
those 3 methods mentioned are declared in the RegisterMonoModules.cpp in the Libraries folder, usually. so take that cpp file and add it to your target's Build Phases > Compile Sources
then if you have additional SDK's integrated that are not added to the 'Compile Sources' the new build will throw some other errors. just make sure to add the wrapper .mm files from the sdk's to your Compile Sources. Usually one .mm file per sdk. (e.g. for unity facebook sdk it's FbUnityInterface.mm file)
hope this helps

XCode file not compiling

I'm getting the following two errors via xcode:
Warning: no rule to process file '$(PROJECT_DIR)/SQLite Toolbox/en.lproj/MainWindowController.m' of type file for architecture x86_64
Followed by:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_MainWindowController", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
Previously my project was building just fine, but I attempted to do some localization. I had my MainWindowController.xib highlighted and choose the localize option.
After that, the project stopped compiling. It looks to me that for some reason XCode is refusing to compile my MainWindowController.m, but i'm not sure how to go about fixing that. (I have confirmed it does exist in the Build Phase Compile Source steps.
Any ideas on how I could fix this?
That sounds as if you inadvertently have localized the "MainWindowController.m" file.
The following steps worked in my test project to fix that situation:
Remove "MainWindowController.m" from your project (using the "Remove Reference" option!)
In the Finder, move "MainWindowController.m" from the "en.lproj" folder back to the main folder.
Drag "MainWindowController.m" onto the Xcode project to add it again.

static Library in Xcode 4

I am too much of this Static Libary thing in Xcode 4.X
Following are the steps that I usually do..
1)For making a static libary , I open Xcode , new , static libary , and then by adding some classes in the project .. then build phases ->copy headers -> add all headers here one by one,and then i build up the project
when run on ios simulator -> static libary does not created ..(red color)
when run on ios device - > static library gets created..
2) for using the library..
I make a new Project , then i "add files to project" and also "copy if needed" the following 2 files..
.a file (i.e.static library)
folder consisting the headers of library files
Now when I try to import a header file in my project , there is no "suggestion" appear ...but still i write and it does not give an error "header file not found"...
but when I run the project it gives the error like:
ld: warning: ignoring file
/Users/Subodh/Library/Developer/Xcode/DerivedData/LibraryImporting_test-cbchzzjdcehzvfgwmzbvifrnrwgk/Build/Products/Debug-iphoneos/libLibraryImporting_test.a,
file was built for archive which is not the architecture being linked
(i386):
/Users/Subodh/Library/Developer/Xcode/DerivedData/LibraryImporting_test-cbchzzjdcehzvfgwmzbvifrnrwgk/Build/Products/Debug-iphoneos/libLibraryImporting_test.a
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_LibraryImporting_test", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Plz guide me....point out if get wrong at some step....help plz
it will be better if someone mentions all the steps as i have done in making a library and using it in a project...it will be a great help
The key to the issue is this part of the error message:
file was built for archive which is not the architecture being linked
(i386)
You have imported the library built for the iPhone Device (ARM) by the look of it, and you are trying to use it in the iPhone Simulator which is i386.
What I would recommend is using an Xcode Workspace where the static library project is one of the projects and the iPhone app is another project. This way Xcode will build the library, as required, for Debug/Release and Device/Simulator.

Resources