android-ndk-r10e开启C++11,编译TEMP_FAILURE_RETRY错误

在使用select来操作socket的时候,一般都是会这么写

int err = TEMP_FAILURE_RETRY(select(socket_fd + 1, NULL, &set, NULL, const_cast<struct timeval*>(&timeout)));

其中的“TEMP_FAILURE_RETRY”宏在“unistd.h”中的定义如下:

/* Used to retry syscalls that can return EINTR. */
#define TEMP_FAILURE_RETRY(exp) ({         \
    typeof (exp) _rc;                      \
    do {                                   \
        _rc = (exp);                       \
    } while (_rc == -1 && errno == EINTR); \
    _rc; })

正常情况下,编译是没问题的。但是当在“Application.mk”中增加

APP_CPPFLAGS += -std=c++11

之后,发现编译不通过了。报告“error: 'typeof' was not declared in this scope”。

解决方法:

APP_CPPFLAGS += -std=gun++11

“c++11”和“gnu++11”的差别:

“gnu++11”增加了很多的扩展“c++11”的功能,功能更加多,具体的扩展参考Extensions to the C++ Language

发布者

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注