2

I'm having trouble creating a swift static library which uses external cocoa pods libraries (SSZipArchive).

I'm getting the following error:

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]​

I have no clue why is this happening.

Cœur
  • 37,241
  • 25
  • 195
  • 267
danielrvt
  • 10,177
  • 20
  • 80
  • 121

2 Answers2

3

You cannot create static Swift libraries.

It was a 'bug' but then the Apple engineers decided to state this is intended behaviour. I needed to make static libraries myself and I am currently SOL on it.

Xcode does not support building static libraries that include Swift code.

Aggressor
  • 13,323
  • 24
  • 103
  • 182
  • I think they are waiting for Swift to become stable. Since static libraries are rarely updated, it would be risky if you ship a .a with Swift 1 and it breaks someone app with Swift 1.2. – NSRover Mar 17 '15 at 10:15
  • 1
    That makes sense @Nirbhay - would you have an alternative to a static library for sharing code among projects? – Zorayr May 27 '15 at 04:37
  • @Zorayr is using Objective-C not an option for you? – NSRover May 27 '15 at 08:45
  • @Nirbhay the code is in Swift, I am extracting it out into a library - I found that Cocoa Touch Framework works out for Swift, not really sure about the difference and which one is recommended. – Zorayr May 27 '15 at 16:08
  • 1
    @Zorayr Frameworks are only supported iOS8+. So if you don't care about support for iOS 7 I think they are a much better option moving forward. I am not sure about Swift support on frameworks though. – NSRover May 28 '15 at 05:51
  • 1
    Until now it still not support static library in Swift. And framework doesn't work in iOS 7. Anyway Apple think it's not their problem. – Zhou Hao Aug 13 '15 at 10:00
3

@Aggressor is correct about the current state of affairs, but even if (when) Swift does allow the creation of static libraries, you must not do this. Third-party libraries must never be incorporated into a static library. This leads to all kinds of build conflicts later if the consumer also includes those libraries (or if another static library does). For more information (and links to even more information), see this ObjC version of the question. If Swift ever supports this, it will be the same issue. The final executable should link together all your libraries.

Community
  • 1
  • 1
Rob Napier
  • 286,113
  • 34
  • 456
  • 610