This project has moved. For the latest updates, please go here.

'Failed to import bridging header'


Hi, I've been doing a lot of work to get Swift usable in a cross-platform way (Mac, iOS, Linux, Android, Raspberry Pi). I heard about this Windows port so I thought I would give it a try.

Using the prebuilt Visual Studio 2015 binaries for the command line swift and swiftc executables provided by the Swift for Windows page, I am able to build and run a trivial Swift program (e.g. print("Hello World").

So my next step is to use a bridging header. The way I'm approaching cross-platform is that I have a bunch of already cross-platform C libraries (e.g. SDL) which I bind to Swift. Then you can write cross-platform Swift code. But for this to work, I need a bridging header.

When I try specifying a bridging header, I get the error "failed to import bridging header".

Any ideas on how to get this working?



ianba3 wrote Apr 17 at 7:23 PM

I get the same error, and here is what I've tried:

print("Hello: \(getIntFromCPP())")
int getIntFromCPP();
Command line:
swiftc -c Hello.swift -o Hello.obj -import-objc-header Hello-Bridging-Header.h
With the error:
<unknown>:0: error: failed to import bridging header 'Hello-Bridging-Header.h'

tinysun wrote Apr 20 at 11:27 AM

Swift for Windows version-1.5 and the MinGW-w64 compiler toolkit will be needed for my demo.
clang++ -c Foo.cpp -o Foo.o

extern "C" int getIntFromCPP()
    return 2017;
c:\SwiftForWindows\Swift\bin\swiftc Hello.swift -o Hello.exe  -import-objc-header Hello-Bridging-Header.h Foo.o
will generate Hello.exe.
c:\SwiftForWindows\My Programs>Hello
Hello: 2017
You can use two step to build the Hello.
c:\SwiftForWindows\Swift\bin\swiftc -c Hello.swift -o Hello.o  -import-objc-header Hello-Bridging-Header.h
c:\SwiftForWindows\Swift\bin\swiftc Hello.o Foo.o -o Hello.exe
Remember that you should use '.o' as the object file extension.

-Han Sangjin

ianba3 wrote Apr 20 at 11:19 PM

Thank you! I see that you posted version 1.5 today:

ewing21 wrote Apr 21 at 12:06 AM

So I'm still interested in how to get Visual Studio working (possibly with Microsoft's clang add-on C2 compiler). I have a pile of MSVC built C libraries that I want to link against via bridging header, and mixing MinGW and MSVC is going to cause massive pain.

Any advice on how to advance the VS side of things?

tinysun wrote Apr 21 at 3:00 AM

Sorry, I'm currently focussing on MinGW port.
This URL will be helpful. (