为什么 struct 声明不能在 Android NDK 中编译?

use*_*461 3 c c++ android struct android-ndk

如何使用 Android NDK 编译结构体?

以下声明(适用于 g++)

#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netdb.h>
#include <cstring>
#include <fstream>
#include <sstream>

//header construction here...
    private:
      struct sockaddr_in serv_addr;
Run Code Online (Sandbox Code Playgroud)

给出错误:

error: field 'serv_addr' has incomplete type
struct sockaddr_in serv_addr;
                   ^
Run Code Online (Sandbox Code Playgroud)

Dav*_*rry 5

你需要添加 #include <netinet/in.h>