Googling around, I found several blog entries, some old and no longer valid it seems, that attempt to explain how to use a C library from Swift. Doing so appears to involve a lengthy process or creating a wrapper and a bunch of files.
However I just want to use a single C function, not a library, and I'm coming at this from the point of view that Swift Should Do It Right, instead of the alternative position that Swift Should Be Unnecessarily Complex.
Therefore I am wondering why all this wrapper business is even necessary. Is there perhaps a simpler, more minimalist way to call a C function from Swift? Suppose I don't even have a library, I have just a .c file or its compiled .o file.
I just need to
tell swiftc what the prototype for the C function is.
In the case of puts, it's in the C standard library, so you should be able to import the C standard library module for your platform (import Darwin on Apple platforms, or import Glibc on Linux). You can also pass Swift string literals directly as C char* arguments:
You could also import it from Foundation. Either with import Foundation or import func Foundation.puts, then you don't have to worry about which platform you're on.