Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
levigroker opened this issue Mar 1, 2013 · 10 comments
Closed
Labels
t3:discussion These are issues that can be non-issues, and encompass best practices, or plans for the future.

Comments

@levigroker
Copy link

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
Copy link
Member

alloy commented Mar 1, 2013

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

@levigroker
Copy link
Author

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
Copy link

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?

@iamraafay
Copy link

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
Copy link
Member

alloy commented Apr 19, 2013

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 as completed Apr 19, 2013
jzapater pushed a commit to jzapater/CocoaPods that referenced this issue Sep 17, 2013
1.3.7 UrbanAirship-iOS-SDK.podspec
@krzyzanowskim
Copy link

empty OTHER_LDFLAGS really is the solution. Thanks.

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

@Whirlwind
Copy link
Contributor

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

I think it is the best solution.

@csotiriou
Copy link

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
Copy link

rubnov commented Jul 7, 2015

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)

@itollei
Copy link

itollei commented Aug 20, 2015

So,What's the best solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t3:discussion These are issues that can be non-issues, and encompass best practices, or plans for the future.
Projects
None yet
Development

No branches or pull requests

9 participants