Linking an Objective-C framework in my swift script using the command line


Let's say, I downloaded an Objective-C framework from the web. I'm going to use this one, just because it showed up first on a GitHub search:

Now, I'm going to use it in my swift script A.swift:

import AppKit
import SDWebImage


I have copied the SDWebImage.framework into my working directory, too.

Now, I'm doing this:

swiftc A.swift -I . -L . -lSDWebImage

But it doesn't work, because error: no such module 'SDWebImage'

Ok, that makes sense, since the .framework isn't really the .dylib, but a directory containing all kinds of things.

So I do this:

swiftc A.swift -I SDWebImage.framework/ -L SDWebImage.framework/ -lSDWebImage

It seems to be smart enough to look for the headers etc., but then this happens:

<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Headers/SDWebImage.h"
[...]/Headers/SDWebImage.h:10:9: error: 'SDWebImage/SDWebImageCompat.h' file not found
#import <SDWebImage/SDWebImageCompat.h>
A.swift:2:8: error: could not build Objective-C module 'SDWebImage'
import SDWebImage

So it says it can't find SDWebImage/SDWebImageCompat.h. Which makes sense, because that's how it is referenced. But of course, all the headers are now in the Headers directory.

What am I doing wrong? What's really going on inside of the compiler?

Ultimately, I'd like to be able to import any Objective-C .framework (or hybrid frameworks with umbrella header), I'm only using this one as a test.

Thank you in advance,

best regards,


No Swift compiler on hand at the moment, but with Clang you link frameworks with -framework SDWebImage and use -F to control the framework include path. If that doesn’t do it, it’s almost certainly documented in swift --help

1 Like

Thank you, this seems to work

Terms of Service

Privacy Policy

Cookie Policy