My Xcode project has a two frameworks: one of them requires other linker flags -ObjC in order to compile, but when the -ObjC flag is used, the second can't compile and shows many errors.
Is there a way to compile a project without the -ObjC flag when a specific framework requires it?
I haven't tried this but it might very well work:
what -objc does is basically loading symbols (of categories) that are the linker doesn't find because they don't seem used. See this answer for more details:
Why is the -ObjC linker flag needed to link categories in static libraries? (LLVM)
so you should very well be able to emulate this with the -all_load linker flag
BUT that doesn't help you because that would still affect all your linked libraries
BUT you can tell load_all to only affect certain libs.. you'd use -force_load %NAMEOFLIB%
That way, you might get around -ObjC
Related
What's the difference between Build Phases -> Link Binary with Libraries or Build Settings -> Linker Flags?
The former does not seem to allow you to specify between Debug vs Release, and the frameworks specified within it also don't seem to match up with the latter.
Note: I have checked existing posts on SO, haven't found one that answers this accurately.
Xcode translates libraries in Build Phases – Link Binary With Libraries into linker flags: -lsome or -framework Some.
Build Phases is a somewhat abstract view on build process. You have this linker step listed here, but it is one-way – it doesn't reveal what is already there for linker in Linker Flags, it only adds new flags to linker.
"Optional" libraries translate to weak linking: -weak-lsome and -weak_framework Some
I need to link two libraries in a project, Cordova and a library from a hardware manufacturer. The hardware manufacturer's library gives an error if you compile with -ObjC but Cordova requires -ObjC flag.
Is there a way to force the -ObjC flag for a library and not for the other (or vice-versa)?
Thanks!
Specific error: Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_MPMusicPlayerController", referenced from:
objc-class-ref in libdtdev.a(AudioStream.o)
It looks like a posted the question just before I figured it out (like always). Instead of deleting the post, someone might want to know what the solution was...
If I keep the -ObjC flag in place and add the frameworks it's complaining about to the "Link Binary With Libraries" section (in my case "MediaPlayer.framework").
I have this error in objective c
-fobjc-link-runtime it say's file not found. I've been googling but failed to get what caused the error. I'm building it on a xcode4.5 environment. using ios6 as base sdk. Any ideas?
Just had the same issue. Turns out it was due to my having left a -force_load option in the Other Linker Flags, that turned out to be followed by -fobj-link-runtime, causing the linker to think that was a library.
That looks an awful lot like a spurious linker flag that leaked through from some kind of ObjC testing harness.
I.e. you need to go to the build settings editor in Xcode, find whatever is setting that particular flag, and remove it.
Some libraries require the -all_load linker flag when linking to an Xcode project. However, this leads to a linker error if there are symbol conflicts among libraries. The solution is to use -force_load, which effectively lets you use -all_load on some libraries, but not on others.
However, this in turn leads to a new problem, at least for me. Whenever I use -force_load with a relative path to a library, the linker always finds symbol conflicts between the library and itself. It appears that the linker thinks that the library with its absolute path and the library with its relative path are different libraries, and therefore finds conflicts between the library and itself.
I can avoid this by using an absolute path with the flag. But this is not a wonderful solution, as it is convenient to keep source code for libraries within my documents directory. But the path to the documents directory will be different on other machines.
Question: Can anyone get force_load to work with a relative path to the library?
EDIT: for background information, see this question
With Xcode 4, if you include the library project into your app project, then you can add this to the Other Linker Flags:
-force_load $(BUILT_PRODUCTS_DIR)/<library_name.a>
You still need the dependency, and you need to add the library in the Link Phase list of frameworks and libraries too.
EDIT: Apple now says as of some Xcode 4 release that you can simply use this linker flag: "-ObjC" to get libraries with categories to properly load. That flag is working just fine for me in Xcode 5. People are still up voting this answer, but I suspect that the -ObjC flag is the best solution now.
This worked for me. Like the above answers you still need to include the library in the project.
-force_load $(SRCROOT)/pathToLibraryFromProject/libname.a
For the path it's just the folders in your project that lead to where you put your library, for example BaseFoler/Subfolder/libName.a.
I have a three Objective-C libraries and an Objective-C application.
The application uses library A, library B and library C.
Library A uses library B.
I need to link library C to the project with the -ObjC flag.
(All libraries are static cocoa touch libraries)
But then i get the problem that I get a compiler warning for dubplicate symbols in library B.
When I leave out the -ObjC flag the -ObjC flag, library C is not used properly.
How can i solve this?
Thanks
You can add
force_load
with path to library needed to be loaded with -ObjC
from linker man:
-force_load path_to_archive
Loads all members of the specified static archive library.
Note: -all_load forces all members of all archives to be
loaded. This option allows you to target a specific archive.