一个串口通讯程序,可是编译是总是报assert的错误!!!
#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
应该如何解决阿??