c - 预处理器编译错误#error
问题描述
我使用 Makefile 编译项目,但在编译“amqp_soket.c”文件期间收到此错误:如何解决此错误。请问有什么建议吗?
amqp_socket.c: 在函数'amqp_poll'中: amqp_socket.c:261:2: 错误: #error "poll() or select() is required to compile rabbitmq-c" #error "poll() or select() is required编译rabbitmq-c"
amqp_socket.c:在函数“amqp_poll”中:amqp_socket.c:263:1:警告:控制到达非无效函数的结尾[-Wreturn-type]
int amqp_poll(int fd, int event, amqp_time_t deadline) {
#ifdef HAVE_POLL
struct pollfd pfd;
int res;
int timeout_ms;
/* Function should only ever be called with one of these two */
assert(event == AMQP_SF_POLLIN || event == AMQP_SF_POLLOUT);
start_poll:
pfd.fd = fd;
switch (event) {
case AMQP_SF_POLLIN:
pfd.events = POLLIN;
break;
case AMQP_SF_POLLOUT:
pfd.events = POLLOUT;
break;
}
timeout_ms = amqp_time_ms_until(deadline);
if (-1 > timeout_ms) {
return timeout_ms;
}
res = poll(&pfd, 1, timeout_ms);
if (0 < res) {
/* TODO: optimize this a bit by returning the AMQP_STATUS_SOCKET_ERROR or
* equivalent when pdf.revent is POLLHUP or POLLERR, so an extra syscall
* doesn't need to be made. */
return AMQP_STATUS_OK;
} else if (0 == res) {
return AMQP_STATUS_TIMEOUT;
} else {
switch (amqp_os_socket_error()) {
case EINTR:
goto start_poll;
default:
return AMQP_STATUS_SOCKET_ERROR;
}
}
return AMQP_STATUS_OK;
#elif defined(HAVE_SELECT)
fd_set fds;
fd_set exceptfds;
fd_set *exceptfdsp;
int res;
struct timeval tv;
struct timeval *tvp;
assert((0 != (event & AMQP_SF_POLLIN)) || (0 != (event & AMQP_SF_POLLOUT)));
#ifndef _WIN32
/* On Win32 connect() failure is indicated through the exceptfds, it does not
* make any sense to allow POLLERR on any other platform or condition */
assert(0 == (event & AMQP_SF_POLLERR));
#endif
start_select:
FD_ZERO(&fds);
FD_SET(fd, &fds);
if (event & AMQP_SF_POLLERR) {
FD_ZERO(&exceptfds);
FD_SET(fd, &exceptfds);
exceptfdsp = &exceptfds;
} else {
exceptfdsp = NULL;
}
res = amqp_time_tv_until(deadline, &tv, &tvp);
if (res != AMQP_STATUS_OK) {
return res;
}
if (event & AMQP_SF_POLLIN) {
res = select(fd + 1, &fds, NULL, exceptfdsp, tvp);
} else if (event & AMQP_SF_POLLOUT) {
res = select(fd + 1, NULL, &fds, exceptfdsp, tvp);
}
if (0 < res) {
return AMQP_STATUS_OK;
} else if (0 == res) {
return AMQP_STATUS_TIMEOUT;
} else {
switch (amqp_os_socket_error()) {
case EINTR:
goto start_select;
default:
return AMQP_STATUS_SOCKET_ERROR;
}
}
#else
#error "poll() or select() is needed to compile rabbitmq-c"
#endif
}
解决方案
您可以使用 -D 和 CFLAGGS 在源代码中定义宏。
make CFLAGS=-DHAVE_POLL
现在
#ifdef HAVE_POLL
变成真的
编辑
还要检查 Makefile 本身是否使用 $(CFLAGS) 作为参数
推荐阅读
- java - 清理 Excel 表格(替换文本)
- c++ - c ++三角函数返回意外值
- python - 自动化 C 脚本以处理多个文件
- shell - 从命令行参数将密码传递给 CVS 登录
- powerapps - PowerApps:如何从表导航到另一个表
- android - 应用程序因错误而崩溃:Android 版本 >= 6.0 上不存在 String#value 字段
- java - eclipse中的Servlet部署结构不同
- c# - DataGridView,一些双打格式为指数
- javascript - 第二个待办事项编辑单击将在第一个待办事项上呈现文本区域
- material-ui - 如何在material-ui中居中?