Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Static Library fails to link because of OTHER_LD_FLAGS from Pods.xcconfig #826

Closed
levigroker opened this Issue · 9 comments

8 participants

@levigroker

I recently created a Static Library project, created my Podfile and added a pod which requires zlib. After a pod install the Pods.xcconfig contains

OTHER_LDFLAGS = -ObjC -lz

Which is not unexpected, however, when trying to build I get this output:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lz
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lz is not an object file (not allowed in a library)
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool failed with exit code 1

After some research it would seem that specifying these kinds of flags for a static library is not correct. Once I overrode the Pods.xcconfig OTHER_LDFLAGS in my target the error did not persist.

@alloy
Owner

Can you elaborate on what you had to change and into what and why?

@levigroker

I had to change my target's OTHER_LD_FLAGS to be empty. As to why, I'm no static library expert, but I read this post on SO which led me to remove the flags.

@nickcurran

I get this as well. If (from example at http://docs.cocoapods.org/specification.html#libraries) I add s.library = 'z' to the podspec I'm building and using internally, my consuming project fails to build and has OTHER_LDFLAGS set to -lz. I've also seen this from another library that libz, ZipArchive.

How can this be resolved? What's the best approach for writing static libraries that include pods that required linked libraries, like libz or libxml?

@mohdabdurraafay

These issues also occurs when your Workspace Build settings are pointing to Legacy. Change it to Xcode Defaults or Custom to get this working.

@alloy
Owner

This ticket got lost in my overview.

I understand the issue now. The important thing is to understand that typically you don’t link static libraries against other static libraries. You either pull them all into an application, or you use lipo to stitch them all together into one static library.

In any case, if you really want to build a non Pods static library with a Pods xcconfig file, you can override OTHER_LDFLAGS in the non-Pods static libraries build settings. In fact, this is what CocoaPods does with the Pods static libraries in the Pods.xcodeproj project, so you can check that for an example.

@alloy alloy closed this
@krzyzanowskim

empty OTHER_LDFLAGS really is the solution. Thanks.

Maybe it can be reconsider for static library targets to include this solution.

@Glavin001 Glavin001 referenced this issue in Streamlyne/Cocoa-SDK
Open

Setup Unit Testing #13

1 of 2 tasks complete
@Whirlwind
Maybe it can be reconsider for static library targets to include this solution.

I think it is the best solution.

@csotiriou

I am still experiencing this issue with the latest cocoa pods.

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC 
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lc++
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lc++ is not an object file (not allowed in a library)
@rubnov

I'm having the same issue. Looks like a regression in Xcode 6.4 when building libraries.

warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified, -all_load invalid
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC -ObjC 
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lPods-AFNetworking
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lPods-AFNetworking is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lPods-CocoaLumberjack
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lPods-CocoaLumberjack is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lPods
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lPods is not an object file (not allowed in a library)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.