Closed deanmao closed 9 years ago
There have been some issues that led to the use of the -ObjC
solution. However I've not been involved with them and I'm not familiar with the reasons that led to the current implementation. I need to dig the issue. However in the meanwhile it would be great if you could provide a concrete example of the issues that you have been experiencing.
Hi yes, I made a blog post about it: http://www.deanmao.com/2012/12/31/linker-error-using-cocoapods/
The short story is that the official opencv ios framework has a few missing symbols in their library, but these symbols are almost never accessed so it will never cause a runtime exception. Using -ObjC forces the linker to load all frameworks and check for missing symbols so the linking step will fail. The simple fix is make libPods.a be fully loaded while leaving everything else alone.
I see, thanks for the detailed report.
Awesome report, @deanmao, thanks!
My 2 cents in this is that the -force_load should be used specific to each pod that needs it.
I'm having problems using the Parse SDK without the Facebook SDK with CocoaPods because of this. I manually removed the -ObjC flag all together and it fixed the parse-pod-without-facebook issue but I've other pods that needs the flag and those started to give me errors.
Did you try to replace the -ObjC
flag with -force_load
?
Do you mean -force_load
only libPods.a
? it wouldn't work because everything (Parse and Facebook) are pods.
I'm working on providing an official CocaPods podspec file for Parse, and running into this too. The Facebook SDK shouldn't be required, but CocoaPods injects -objc which would require us to add the Facebook SDK to the podspec as a dependency unnecessarily.
I managed to make the Parse pod work without facebook dependency by:
-ObjC
by -force_load $(TARGET_BUILD_DIR)/libPods.a
in Pods.xcconfig
Pods-Parse
target dependency from the Pods
targetlibPods-Parse.a
to my main targetI'm not expert in Xcode projects builds but it seems that one way to make this work would be to add an option in the Podspec
to leave the library generated by the pod outside of the libPods.a
and of course replace -ObjC
by -force_load $(TARGET_BUILD_DIR)/libPods.a
in Pods.xcconfig
I kept digging a bit and I guess what @fcy was proposing is not ideal for CocoaPods since it will mean putting more dependencies between the xcodeproj and the xcworkspace...
Anyway I added this in my Podfile as a dirty fix to do what I was doing manually before except that I need to add manually once libPods-Parse.a
The first part is pretty awful and I would suggest that it would be replaced in CocoaPods source directly.
post_install do |installer_representation|
# Replace -ObjC by -force_load
path = installer_representation.sandbox_root + 'Pods.xcconfig'
f = File.open(path, "r")
g = File.open(path.to_s + '.tmp', "w")
f.each_line do |line|
line.sub! '-ObjC', '-force_load $(TARGET_BUILD_DIR)/libPods.a'
g.puts line
end
f.close
g.close
File.rename(g.path, f.path)
# Remove target dependency from Pods target
installer_representation.project.targets.each do |target|
target.dependencies.select!{|d| d.target.name != 'Pods-Parse' }
end
end
Issue has been confirmed by @joelparsons
This is an incredibly long running issue. Any updates?
@fatuhoku I ended up using the @knshiro's suggestion. Works great, but not ideal.
I think we can close this one out.
@alloy ping?
@segiddins Yeah I think so too, especially wit frameworks on the horizon.
I'm sorry, but why was this issue closed? It's affecting me severely, even with the latest CocoaPods v0.37.1.
I've got some C++ libraries that simply don't jive with the -ObjC linker flag.
@MattHillebrandHTC please open up a new issue that includes a sample project?
It's the same issue... I also don't think my company would like me posting their C++ libraries publicly :)
well without a sample project, we're not going to be able to track this down. Doesn't have to be your company's lib, but we need something we can run to see the problem in order to fix it,
With or without CocoaPods, I can't use the linker flag "-ObjC" in my project. If I use "-force_load
I would have recommended using frameworks to integrate, but apparently we are still supplying -ObjC
there, I think that is definitely superfluous. I have created #3537 to change that.
Thank you!
Hi,
We are getting errors even after adding libPods.a in other linker flag,
Targets in Build Settings :- Other Linker Flags :- Remove -ObjC and add -force_load $(TARGET_BUILD_DIR)/libPods.a but after adding the above line we are getting below errors :-
ld: file not found: /Users/abc/Library/Developer/Xcode/DerivedData/MyApp-cti.........yl.........ifas/Build/Products/Debug-iphonesimulator/libPods.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And our Pods.xcconfig
file is lock we can't able to edit -ObjC by -force_load $(TARGET_BUILD_DIR)/libPods.a in Pods.xcconfig
Any help appreciated
I noticed that CocoaPods will auto inject
-ObjC
into the linker flags for your project. This flag causes all symbols to be loaded and may cause errors with other existing frameworks that may not like this flag. The fix would simply be to use a more "targeted" flag as described in Apple's QA 1490: http://developer.apple.com/library/mac/#qa/qa1490/_index.htmlBasically, the fix would be to use something like this as the linker flag instead:
-force_load $(TARGET_BUILD_DIR)/libPods.a
This would have the same desired effect as
-ObjC
without any of the undesirable side effects.