一个串口通讯程序,可是编译是总是报assert的错误!!!

wanghi 2005-08-01 10:29:39
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define RCV_LEN 32
#define SND_LEN 16
#define TIMES 3

void receive(int fd)

{int file_desc,errorcode;
char rec_buf[33];
file_desc=fd;
errorcode=read(file_desc,rec_buf,RCV_LEN);
assert(errorcode>=0);
printf("The received string is %s",rec_buf);
}

void send (int file_d)

{int file_desc,errorcode,fd;
char snd_buf[17];
file_d=fd;
printf("Please enter a string to send(<=16 characters)");
scanf ("%s",snd_buf);
errorcode=read(file_desc,snd_buf,SND_LEN);
assert(errorcode>=0);
printf("You have already send %s",snd_buf);

}


int main()
{
int fd,i;
char pathname[11]="/dev/ttys";
char portnum[2];
printf("pleas select which serial port you choose to test,");
printf("You should input 0 or 1 or 2 or 3");
scanf("%s",portnum);
strcat(pathname,portnum);
fd=open(pathname,O_RDWR,0666);
assert(fd>=0);
for (i=0;i<TIMES;i++) { send(fd); receive(fd); }
return 0;
}


编译结果:
/tmp/ccwPzljQ.o(.text+0x30): In function `receive':
: undefined reference to `assert'
/tmp/ccwPzljQ.o(.text+0xa1): In function `send':
: undefined reference to `assert'
/tmp/ccwPzljQ.o(.text+0x159): In function `main':
: undefined reference to `assert'
collect2: ld returned 1 exit status

应该如何解决阿??
...全文
319 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
NC 2005-08-02
  • 打赏
  • 举报
回复
#include <assert.h>
RobbieHu 2005-08-02
  • 打赏
  • 举报
回复
assert不在stdlib.h中,应该在assert.h中。
wanghi 2005-08-01
  • 打赏
  • 举报
回复
我又不是看不明白编译结果上写的英文,不是已经#include <stdlib.h>了吗??还要怎么定义啊???应该怎么改动啊???您至少要说清楚吧!!!!!!
NC 2005-08-01
  • 打赏
  • 举报
回复
assert没定义

23,110

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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