Can't find some socket types on Linux with C++ interop

I'm using Swift 5.10 on Ubuntu. After adding .interoperabilityMode(.Cxx) to the Swift settings, the Swift compiler is no longer able to find in_addr or sockaddr_in in scope. Any ideas? Importing Glibc doesn't help.

There are some issues with the C and now C++ modulemaps used by the Swift compiler and their layering, that have slowly been iterated on but still have issues like this. I suggest you file a compiler issue and tag one of the C++ Interop people on it.

So if I try something like:

public typealias in_addr = in_addr_t

which is deliberately wrong, I get the error:

error: value of type 'in_addr' (aka 'UInt32') has no member 's_addr'

which suggests that the header file is being imported, just somehow the struct definition is ignore (header snippet below).

/* Internet address.  */
typedef uint32_t in_addr_t;
struct in_addr
    in_addr_t s_addr;

This gets the package compiling with C++ interop enabled but still breaks on module import into a foreign package. I think I think the most expeditious solution will be just to remove the C++ interop dependency.

import CoreFoundation

public typealias in_addr = CoreFoundation.in_addr
public typealias sockaddr_in = CoreFoundation.sockaddr_in
1 Like