Use a module map to import C headers
suggest changeA module map can simply import mymodule
by configuring it to read C header files and make them appear as Swift functions.
Place a file named module.modulemap
inside a directory named mymodule
:
Inside the module map file:
// mymodule/module.modulemap
module mymodule {
header "defs.h"
}
Then import
the module:
// demo.swift
import mymodule
print("Empty color: \(Color())")
Use the -I directory flag to tell swiftc
where to find the module:
swiftc -I . demo.swift # "-I ." means "search for modules in the current directory"
For more information about the module map syntax, see the Clang documentation about module maps.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents