Declaration of 'u_char' must be imported f

2019-07-22 14:57发布

问题:

I imported "if_dl.h" in my Swift framework to use sockaddr_dl like this :

module net [system]  [extern_c] {

     module if_dl {
         umbrella header
         "/Applications/Xcode_7.3.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/net/if_dl.h"
         module * {export *}
     }

 }

and now I am getting this error:

Declaration of 'u_char' must be imported from module 'Darwin.POSIX.sys.types' before it is required

I tried to add "import Darwin" in the class code but it's not resolving the problem.

回答1:

I resolved the problem,

Module "types" have to be inside the module "net" and it have to be added before adding "if_dl"

 module net [system]  [extern_c] {

     module types {
         header "/usr/include/sys/types.h"
         export *
     }

     module if_dl {

         header
         "/usr/include/net/if_dl.h"
         export *
     }

 }