求助:关于编译错误游离等
以下程序:
* sndrec.c */
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/soundcard.h>
#define LENGTH 3
#define RATE 8000
#define SIZE 8
#define CHANNELS 1
char buf[LENGTH*RATE*SIZE*CHANNELS/8];
int main()
{
int fd;
int arg;
int status;
fd = open("/dev/dsp", O_RDWR);
if (fd < 0) {
perror("open of /dev/dsp failed");
exit(1);
}
arg = SIZE;
status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
if (status == -1)
perror("SOUND_PCM_WRITE_BITS ioctl failed");
if (arg != SIZE)
perror("unable to set sample size");
arg = CHANNELS;
status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
if (status == -1)
perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
if (arg != CHANNELS)
perror("unable to set number of channels");
arg = RATE;
status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
if (status == -1)
perror("SOUND_PCM_WRITE_WRITE ioctl failed");
while (1) {
printf("Say something:\n");
status = read(fd, buf,sizeof(buf) );
if (status != sizeof(buf))
perror("read wrong number of bytes");
printf("You said:\n");
status = write(fd, buf, sizeof(buf));
if (status != sizeof(buf))
perror("wrote wrong number of bytes");
status = ioctl(fd, SOUND_PCM_SYNC, 0);
if (status == -1)
perror("SOUND_PCM_SYNC ioctl failed");
}
return 0;
}
我用的FC6编译出错:
sndrec.c:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
In file included from sndrec.c:2:
/usr/include/unistd.h:325: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/unistd.h:331: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/unistd.h:469: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
In file included from sndrec.c:2:
/usr/include/unistd.h:566: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘confstr’
/usr/include/unistd.h:738: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/unistd.h:774: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/unistd.h:821: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
In file included from sndrec.c:2:
/usr/include/unistd.h:843: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/unistd.h:850: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/unistd.h:861: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/unistd.h:863: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/unistd.h:881: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/unistd.h:882: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
In file included from sndrec.c:6:
/usr/include/stdlib.h:140: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__ctype_get_mb_cur_max’
/usr/include/stdlib.h:455: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:485: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:487: 错误:非空的实参操作数号越界(实参 1,操作数 4)
/usr/include/stdlib.h:589: 错误:expected ‘)’ before ‘__size’
/usr/include/stdlib.h:591: 错误:expected ‘)’ before ‘__nmemb’
/usr/include/stdlib.h:600: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
In file included from /usr/include/stdlib.h:612,
from sndrec.c:6:
/usr/include/alloca.h:33: 错误:expected ‘)’ before ‘__size’
In file included from sndrec.c:6:
/usr/include/stdlib.h:617: 错误:expected ‘)’ before ‘__size’
/usr/include/stdlib.h:622: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:622: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:776: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:776: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:777: 错误:非空的实参操作数号越界(实参 1,操作数 5)
/usr/include/stdlib.h:781: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:781: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:782: 错误:非空的实参操作数号越界(实参 1,操作数 4)
/usr/include/stdlib.h:854: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:857: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:861: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:865: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:874: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:878: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdlib.h:885: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘mbstowcs’
/usr/include/stdlib.h:888: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘wcstombs’
In file included from /usr/include/_G_config.h:44,
from /usr/include/libio.h:32,
from /usr/include/stdio.h:72,
from sndrec.c:7:
/usr/include/gconv.h:72: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/gconv.h:88: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/gconv.h:97: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/gconv.h:174: 错误:expected specifier-qualifier-list before ‘size_t’
In file included from /usr/include/stdio.h:72,
from sndrec.c:7:
/usr/include/libio.h:328: 错误:expected specifier-qualifier-list before ‘size_t’
/usr/include/libio.h:360: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:369: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:485: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_IO_sgetn’
In file included from sndrec.c:7:
/usr/include/stdio.h:308: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:315: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:357: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:359: 错误:格式字符串实参不是字符串玵型
/usr/include/stdio.h:361: 错误:expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:610: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
/usr/include/stdio.h:616: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
/usr/include/stdio.h:638: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread_unlocked’
/usr/include/stdio.h:640: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite_unlocked’
sndrec.c: 在函数 ‘main’ 中:
sndrec.c:44: 错误:程序中有游离的 ‘\302’
sndrec.c:44: 错误:程序中有游离的 ‘\240’
sndrec.c:44: 错误:程序中有游离的 ‘\302’
sndrec.c:44: 错误:程序中有游离的 ‘\240’
sndrec.c:44: 错误:程序中有游离的 ‘\302’
sndrec.c:44: 错误:程序中有游离的 ‘\240’
sndrec.c:44: 错误:提供给函数 ‘read’ 的实参太多
sndrec.c:49: 错误:提供给函数 ‘write’ 的实参太多