pthread_rwlock_t 错误

jackyloncoln 2010-06-24 10:28:54

struct bcentry {
struct in6_addr our_addr; /* Address to which we got BU */
struct in6_addr peer_addr; /* MN home address */
struct in6_addr old_coa; /* Previous care-of address */
struct in6_addr coa; /* MN care-of address */
struct timespec add_time; /* When was the binding added or modified */
struct timespec lifetime; /* lifetime sent in this BU, in seconds */
uint16_t seqno; /* sequence number of the latest BU */
uint16_t flags; /* BU flags */

uint16_t nonce_coa;
uint16_t nonce_hoa;
int type; /* Entry type */
int unreach; /* ICMP dest unreach count */
int tunnel; /* Tunnel interface index */
int link; /* Home link interface index */

int id; /* For testing */

/* Following fields are for internal use only */
struct timespec br_lastsent; /* BR ratelimit */
int br_count; /* BR ratelimit */

pthread_rwlock_t lock; /* Protects the entry */
struct tq_elem tqe; /* Timer queue entry for expire */

void (*cleanup)(struct bcentry *bce); /* Clean up bce data */
};



这是定义的一个结构体,在“pthread_rwlock_t lock;”这一行出现

error:syntax error before "pthread_rwlock_t"
warning:no semicolon at end of struct or union

在最后一行出现

error:syntax error before '}' token


请问,这是什么原因啊?

...全文
189 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackyloncoln 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 brookmill 的回复:]
引用 3 楼 jackyloncoln 的回复:
但是出现一个undefined reference to "get"
这个函数的声明我放在了头文件“bcache.h”中,实现我放在了“bcache.c”中
另外,我在我的程序中已经包含了这个“bcache.h”头文件了,为什么还是没定义呢?

头文件的作用是声明函数,他只在编译阶段有作用。
"undefined reference"是……
[/Quote]

谢谢了
hallowwar 2010-06-24
  • 打赏
  • 举报
回复
-munix=93 provides the same predefines as GCC 3.3 and 3.4.
-munix=95 provides additional predefines for "XOPEN_UNIX" and
"_XOPEN_SOURCE_EXTENDED", and the startfile unix95.o. -munix=98
provides additional predefines for "_XOPEN_UNIX",
"_XOPEN_SOURCE_EXTENDED", "_INCLUDE__STDC_A1_SOURCE" and
"_INCLUDE_XOPEN_SOURCE_500", and the startfile unix98.o.

1 很纳闷,这就可以解决了问题,解释一下?

2 直接加入绝对路径包含进去试试。
jackyloncoln 2010-06-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 brookmill 的回复:]
要不就试试 -D_XOPEN_SOURCE=500
或者在代码最前面加上 #define _XOPEN_SOURCE 500
[/Quote]

谢谢了,那个错误倒是不出现了

但是出现一个undefined reference to "get"

get是一个函数。

这个函数的声明我放在了头文件“bcache.h”中,实现我放在了“bcache.c”中
另外,我在我的程序中已经包含了这个“bcache.h”头文件了,为什么还是没定义呢?

brookmill 2010-06-24
  • 打赏
  • 举报
回复
要不就试试 -D_XOPEN_SOURCE=500
或者在代码最前面加上 #define _XOPEN_SOURCE 500
brookmill 2010-06-24
  • 打赏
  • 举报
回复
试试 gcc -D_GNU_SOURCE
brookmill 2010-06-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jackyloncoln 的回复:]
但是出现一个undefined reference to "get"
这个函数的声明我放在了头文件“bcache.h”中,实现我放在了“bcache.c”中
另外,我在我的程序中已经包含了这个“bcache.h”头文件了,为什么还是没定义呢?
[/Quote]
头文件的作用是声明函数,他只在编译阶段有作用。
"undefined reference"是链接错误,意思是完成编译之后链接的时候找不到这个函数的实现代码。
这个要看makefile怎么写的,链接的命令行里面是否指定了bcache.c或者bcache.o

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧