Duplicate symbol for class in library and project - objective-c

I am using SBJson classes in my library and having tried to use the library in my project I am having a duplicate symbol error because I am also using these files in the main project.
I can't add prefixes to these files so how does one usually work around this problem ?
I saw other answers that suggest renaming classes with prefixes, yet this isn't really the solution since it's correct that these files have duplicates - it's an open source code.

You could remove the SBJSON (.m) files from the library project target (using the "Build Phases" screen in Xcode) and then project should be able to compile using the SBJSON files that are part of the main project. There might be issues though, if both projects use different versions of the SBJSON library.
Personally I wish all library projects didn't include other libraries but note (in a "Read Me" file or whatever) that it's a dependency and it's up to the developer to include the dependencies in the main project. I've had a lot of issues with duplicate symbols in the past due to this stuff.

Just Go to Build Setting and
search for No Common Blocks and
set it NO.
And build again you will not get this error again.
CheersKP

You can just include the .h files in your project and remove .m for SBJson. That way you can import the .h in you code and it will compile.

Related

AdMob: Could not find auto-linked framework 'FBLPromises'

I have a Objective C project and I want to add AdMob to it. Been following https://developers.google.com/admob/ios/quick-start#objective-c
I get the linker error
ld: warning: Could not find auto-linked framework 'FBLPromises'
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_UIScene"
I'm adding the frameworks manually. I dragged them in.
The tutorial doesn't say anything about the promises framework, but it comes in their download. And if I don't add it, I get a linker error saying a function is missing.
All of the frameworks are in the project and in Link With Binary Libraries list.
I tried deleting them and re-adding them, and quitting Xcode and clean build.
I tried adding framework search paths $(inherited) and $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) and the folder they are in with recursive $(PROJECT_DIR)/Frameworks and all of their exact paths individually also.
I tried adding a new swift file to the project so that it becomes hybrid.
I added -ObjC linker flag to Other Linker Flags, and $(inherited)
The tutorial says to add "GoogleUtilities.framework" But what I downloaded has "GoogleUtilities.xcframework" folder. So I tried adding the folder both as a group and as not, and I tried adding the framework files in the folder only.
I tried making a new project with nothing else.
Can anyone get AdMob to work on an Objective C project with adding frameworks manually?
I have agreed to the latest terms from apple and have a paid developer account.
I had a similar error in a Swift project.
Undefined symbol: _OBJC_CLASS_$_JSContext
In my case the solution was to add the JavaScriptCore.framework to the project.
Figured out the issue for a hybrid project!
The project I was linking to used an ObjC Bridging Header, so I simply needed to import Firebase in the header file:
// ObjC-Bridging-Header.h
#import "Firebase.h"
Not sure if this relates to a pure ObjC project, but you might be able to add a dummy Swift file to make it a hybrid project and use the bridging header.
I had the same error. I had forgotten to add the following libs: nanopb.xcframework, PromisesObjC.xcframework, UserMessagingPlatform.framework - included in GoogleMobileAdsSdkiOS.. I just added the missed libraries and now everything is OK.
Try to add libz.tbd, libc++.tbd, libsqlite3.tbd and StoreKit libraries in Link Binary With Libraries at the Build Phases tab.

Module not found for framework dependency in Xcode

I have a project with multiple framework targets, that also have pods dependencies.
I have:
No circular dependencies between targets
Everything, including pods, is in Objective-C, no Swift at all.
use_frameworks! in Podfile, so all pods are frameworks, not libraries.
Here is my structure:
TUSystemKit depends on TUModels (which is a framework).
TUModels depends on Pods_TUModels (generated by pods).
Pods_TUModels depends on JSONModel
TUModels is automatically linked with its own pod framework (which contains JSONModel).
TUSystemKit has TUModels as target dependency.
TUSystemKit is linked with TUModels.
Visually, the dependencies are like this:
TUSystemKit ➔ TUModels ➔ Pods_TUModels ➔ JSONModel
When I select MyModels as the build target in Xcode, build succeeds. However, when I select TUSystemKit, the build fails, saying that module JSONModel is not found while building module TUSystemKit (TUUser in screenshot belongs to TUModels):
What am I doing wrong? Obviously I shouldn't be explicitly linking against all the frameworks in the dependency tree. Why does TUModels build perfectly but TUSystemKit errs on a module import inside a linked framework's code? Do I need to change something with pods?
After hours of refactoring, I've managed to build my project. I can't tell what exactly was wrong as it took me literally a day to organize all the dependencies and frameworks and it kept failing at a different point, more than a 100 times, but here are some observations to lead to a successful build:
All the public-facing classes are added as public headers to the target, and not to any other target.
All the code (.m files) are in Compile Sources section of the target, and not in any other target.
All the public facing classes' headers are included at umbrella header (a header with the exact same name with the framework)
The application embeds all the custom frameworks (not the pods).
All the files inside a framework target only #import required files within the same target or a file listed on any targets umbrella header that the framework has a dependency on.
Obvious, redundant, but worth noting again: no classes between frameworks should have circular dependencies (e.g. ClassA in FrameworkA depends on ClassB in FrameworkB, while some class in FrameworkB depends on some class on FrameworkA). I had some, and created delegates. Do whatever pattern fits your design: IoT/dependency injection, notifications/publisher-subscriber etc. But do it: separate the concerns clearly.
Try to avoid using same classes in multiple targets. Instead, have it in one target, and make the other target depend on the containing target, creating a dependency chain.
After refactoring many files and playing with project settings, I managed to build and run everything again. My previous setup had various number of combinations of the issues that I mentioned above, messing everything up. After cleaning all the bits and grouping code into functional, modular frameworks, I could build it.
If you came here due to the parse error -> module not found,
in certain occasions you may be forced to add the path manually.
This is...
go to your project at the top
select your project target
select build settings
search the parameter Framework Search Paths under the title Search Paths
add the one where yours is located. Example: (using cocoa pods) $(SRCROOT)/Pods
indicate/set it to be recursive (access to the option by double-clicking your previously added path)
The problem should have been resolved by the 3erd party lib with commands like install / update / build or similar but if it fails and you are stuck, this is an option in order to continue.
In the same tone, if you get an error from pods indicating that
The sandbox is not in sync with the Podfile because the builder is unable to find files like Podfile.lock, then you may consider to go in the same direction adding some user-defined settings:
select build settings
press the '+' symbol, "Add User-Defined Setting".
add this pair:
param= PODS_PODFILE_DIR_PATH value = ${SRCROOT}/.
param = PODS_ROOT value = ${SRCROOT}/Pods
Cheers

106 duplicate symbols for architecture armv7

Working on my iPhone app and trying to build for debug and I get "106 duplicate symbols for architecture armv7"?
I am using the .workspace file because I am trying to use CocoaPods. If I don't use the .workspace and instead use the .xcodeproj I don't get the error, but then I get missing -lPods .
In my project I have the following targets in the Project Navigator.
Pods (blue icon)
MyProject (blue icon)
Restkit.xcodeproj (blue icon)
... all my files
The issue is that Restkit is making reference to "AFHTTPClient.h" and all the other AF code, but I included it via CocoaPods. I tried deleting the AFNetworking folder from the RestKit library, but apparently the Restkit library can't find the Pods version of AFNetworking?
Is there a way to get RestKit to use the Pods version? If not how do I go about removing Pods from my project?
There is a line in one of your .h files where your wrote
#include "___.m"
instead of
#include "___.h"
So I fixed it. After removing the RestKit version of AFNetworking, from the vendor folder, I added it back by dragging into Xcode. It asks which project I want it used/copied to and this time I selected RestKitTest (or whatever the RestKitTesting is named). It works now. Maybe I selected both RestKit and RestKitTest before, which was wrong?
I also came up with same error. Generally this kind of error occurs due to duplicate classes and xibs in project folder. For Example in my project I had these classes twice ServiceRequest.h/.m. Get rid of duplicate ones and you are good to go.
In Build Phases -> Compile Sources, make sure you don't have the same file added twice.
"Duplicate symbols for architecture" issue occurs in two situations:
You added a .m file twice into your project
You're using a static library (.a file) which already includes some classes that you include into the project.
For fixing any of those cases, check the linker error and look for the .o files that are duplicated (sample: Reachability.o).
Then go to the build phases -> compile sources and search the specified files, if any one appears twice delete one of them, if only appears once it means that the file is also included in one of the static libraries added to your project. Delete it from your list of sources to be compiled and try again.
I saw this error when, I did drag and drop my calabash framework onto xcode and selected add to targets option in the window thats shown. Basically there were two references to files added
I had to remove the calabash framework manually
Right way of doing it
copy to calabash framework to project directory
then go to xcode project
Choose target -> Build phases -> Link Binary With Libraries and add the frame work using + button
I have noticed that duplicate symbols are caused for Google analytics after installing cocoaPods as well. Once I removed one of archives, either libGoogleAnalytics_debug.a or libGoogleAnalytics.a duplication has gone. But obviously if I removed debug one I will not be able to run os simulator and vica versa. I know its not the solution, but at least it could give an idea what could be a solution. Will come back to this thread if I will figure out how to have both a files in this case.
Edit:
I was able to solve the issue by upgrading from G analytics version 2 to 3. It has only one library file and I guess this is the reason why we don't get duplicated symbols anymore. I hope it makes sense.

Hide code in static library (iOS Obj-C)

I'm working to create an iOS static library that I wish to sell. I've walked through the steps for the initial builds and have generated the .a/.h output.
When I include these files in a separate project, I don't see any way to browse the contents on the .a file.
HOWEVER, when a line of code in my library crashes the app (like I said, it's still in development), the debugger shows the entire class (.m) file to me. What's up with this?
I don't really understand what all goes into static libraries, and I'm not sure I compiled that version for both simulator and device. Could that have something to do with it? If so, could someone explain why?
Thanks!!!
Don't worry, your source code is not included in the archive (.a) file.
Xcode is smart enough to find the source code file on your computer, based on the debugging information embedded in the file. If you build the library using the "Release" configuration (or otherwise modify the build settings so that debugging symbols are stripped) and don't have the source anywhere on the machine, a developer will have to resort to their knowledge of x86 or ARM assembly to figure out how your code works.
By the way:
Since a lot of Objective-C is handled at runtime, a lot of class names and selector names will be visible in your library. That's just how it works. You could try to obfuscate it, but I think your time is better spent writing more useful code to sell.
If you want to give people a static library for iOS development, you'll want to build versions for the iOS Simulator (x86) and the iOS Device (arm) and then use lipo to combine them into a single fat static library. Search around for "lipo xcode fat static library" for different ways to do this. Some solutions are more convoluted than others.
I had the same issue. #benzado is right about what he has mentioned. But I had to strip debugging symbols to solve the issue. To do so, I had to change Build Settings of project library before build as mentioned below.
Select your Target and go to Build Settings. Set
' Strip Debug Symbols During Copy ' to YES
' Debug Information Format ' to 'DWARF with dSYM File'
' Generate Debug Symbols ' to 'NO'
' Symbols Hidden by Default ' to 'YES'
To see what are these for, refer Apple Build Setting Reference
And build the library using the "Release" configuration. This worked for me.
If you have a project for static library with all .m files on your computer then every copy of this library (.a file) will be symbolicated with its .m file while debugging in xCode.
xCode doesn't search for appropriate .m file through all your disk. It knows the place of original project. So if you distribute only library it fully hides your initial code.
To make sure you can copy your library in some new project then clear .m file in library project.
From this moment any attempt to debug methods of library will give empty file on screen.

Can't Find Framework .h File

I downloaded Andy Potion's "PFLetsMove" framework here and added the Xcode Project to my application's project. I then dragged the framework from that to the Link Binary with Libraries and Copy Files build phases.
Now, if I compile the application with a call to PFMoveToApplicationsFolderIfNecessary() it works fine, so the framework is definitely there. But if I put the line #import "PFLetsMove/PFMoveApplication.h" in the app delegate, I get the following error: 'PFLetsMove/PFMoveApplication.h' file not found.
I've checked the compiled PFLetsMove.framework in the build folder, and PFMoveApplication.h is there. I did the exact same thing with the AquaticPrime framework (import the header) and it works fine. Where am I going wrong here, or is there potentially an issue with how the framework is built?
If you use a framework, you put the file name in angle brackets (i.e. <FrameworkName/FileName.h>), if it's a local file, you use quotes (i.e. "FileName.h"). Note that even if the source file is in a group or subfolder, it is not referenced as such.