error: expected expression before ‘;’ token的问题
来源:互联网 发布:珠江水质监测数据 编辑:程序博客网 时间:2024/05/29 11:41
在借用mosquitto源码,写一个订阅客户端时,使用了pthread_create和pthread_join时出现:
error: expected expression before ‘;’ token的问题:
和
奇怪之处还在于:去掉返回值后,即由:
换成:
就能编译通过。
但是实际执行时还是不能成功创建线程。
经过分析:
自己动手写一个线程程序,没有问题,可以继续执行,于是就怀疑引用的mosquitto的源码产生了该问题,在mosquitto的mosquitto_internal.h文件中有如下代码:
文件dummypthread.h中的内容为:
可见,是头文件dummypthread.h中对pthread_create、pthread_join之类的函数做了宏定义,在使用时调用的就不是系统的pthread_create、pthread_join函数而是这里定义的宏了,因此造成了上述问题。
问题清楚了,其解决办法也就有很多了,
例如可以在mosquitto_internal.h文件开始加上#define WITH_THREADING以去掉对文件dummypthread.h的引用。
error: expected expression before ‘;’ token的问题:
相关代码为:
_ret = pthread_create(&g_clients_db.handle_thread_id, NULL, handle_thread,NULL);if(_ret != 0){printf("[create_handle_thread]:fail pthread_create:handle_thread()\n");return -40;}
和
_ret = pthread_join(g_clients_db.handle_thread_id,NULL); if(_ret != 0){printf("[join_handle_thread]:fail pthread_create:handle_thread()\n");return -4;}
奇怪之处还在于:去掉返回值后,即由:
_ret = pthread_create(&g_clients_db.handle_thread_id, NULL, handle_thread,NULL);
换成:
pthread_create(&g_clients_db.handle_thread_id, NULL, handle_thread,NULL);
就能编译通过。
但是实际执行时还是不能成功创建线程。
经过分析:
自己动手写一个线程程序,没有问题,可以继续执行,于是就怀疑引用的mosquitto的源码产生了该问题,在mosquitto的mosquitto_internal.h文件中有如下代码:
#if defined(WITH_THREADING) && !defined(WITH_BROKER)# include <pthread.h>#else# include "dummypthread.h"#endif
文件dummypthread.h中的内容为:
#ifndef _DUMMYPTHREAD_H_#define _DUMMYPTHREAD_H_#define pthread_create(A, B, C, D)#define pthread_join(A, B)#define pthread_cancel(A)#define pthread_mutex_init(A, B)#define pthread_mutex_destroy(A)#define pthread_mutex_lock(A) #define pthread_mutex_unlock(A) #endif
可见,是头文件dummypthread.h中对pthread_create、pthread_join之类的函数做了宏定义,在使用时调用的就不是系统的pthread_create、pthread_join函数而是这里定义的宏了,因此造成了上述问题。
问题清楚了,其解决办法也就有很多了,
例如可以在mosquitto_internal.h文件开始加上#define WITH_THREADING以去掉对文件dummypthread.h的引用。
- error: expected expression before ‘;’ token的问题
- [Error] expected expression before '%' token
- expected expression before '=' token 问题
- error: expected ')' before '*' token
- error: expected initializer before ‘&’ token
- error: expected expression before 'struct'
- 编译错误:expected primary-expression before '(' token
- 编译出现问题error: expected specifier-qualifier-list before ‘(’ token
- error: expected constructor, destructor, or type conversion before '(' token问题
- swith 引起的: expected expression before 'XXX'的 error
- swith 引起的: expected expression before 'XXX'的 error
- swith 引起的: expected expression before 'XXX'的 error
- 关于【error: expected identifier before ‘,’ token】错误的检查
- mysql-python安装 _mysql.c:602: error: expected expression before ‘)’ token
- Centos 7 成功安装 dosbox 解决 "error: expected primary-expression before ‘,’ token" 错误
- error: expected template-name before '<' token
- error: expected class-name before '{' token
- error: expected class-name before '{' token
- 将文本拆分到不同的单元格中
- oracle11g数据导出不全的问题
- 基于jquery实现一张图片点击鼠标放大再点缩小
- ios 键盘监听
- IT界需求最旺的16项技能
- error: expected expression before ‘;’ token的问题
- 异常:数据库没有有效所有者,因此无法安装数据库关系图支持对象
- ocp历程
- b-Tree & bitmap 索引
- Pig 重写加载函数和存储函数UDF
- Oledb方式读csv文件
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Android图形显示之硬件抽象层Gralloc
- 日志文件夹写满导致网站速度慢