Swift-Linux-Glibc: error: cannot find type 'DIR' in scope

This is an unfortunate manifestation of the issues discussed in Opaque Pointers in Swift.

The specific problem you're hitting is that in glibc the DIR type is opaque: that is, the C header file does not express the layout of the type, only that it exists. In C this has no particular impact at the type level, you just can't dereference the pointer or stack-allocate a value of it. In Swift, however, it entirely changes the type. The reason you're hitting this is that the type is not opaque on Darwin.

In general Swift does not attempt to keep libc types the same across systems (which is good, as it'd be an impossible task). For you, you can either use a typealias to specify the type for each system, or you can convert to OpaquePointer and back on all systems.