代码块无法构建任何包含unistd.h头文件的源代码

我试图在C源代码下构建,但是失败了。

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#define N 3
int add_vector(int v[]);
void error_exit(char *s);
int fork(void);
int pipe(int pd[2]);
int read(int fd,void *buf,unsigned len);
int write(int fd,void *buf,unsigned len);
int main()
{
int a[N][N]={{1,1,1},{2,2,2},{3,3,3}},i,row_sum,sum=0,pd[2];
if(pipe(pd)==-1)
    error_exit("pipe() failed");
for(i=0;i<N;i++)
if(fork()==0){
    row_sum=add_vector(a[i]);
    if(write(pd[1],&row_sum,sizeof(int))==-1)
        error_exit("write() failed");
    return;
}
    for(i=0;i<N;++i)
    {
        if(read(pd[0],&row_sum,sizeof(int))==-1)
            error_exit("read() failed");
        sum+=row_sum;
    }
    printf("Sum of the array=%d\n",sum);
    return 0;
}

int add_vector(int v[])
{
    int i,vector_sum=0;
    for(i=0;i<N;i++)
        vector_sum+=v[i];
    return vector_sum;
}
void error_exit(char *s)
{
    fprintf(stderr,"\nERROR:%s-bye!\n",s);
    exit(1);
}








-------------- Build: Debug in pipe (compiler: Cygwin GCC Compiler)---------------

i686-pc-cygwin-gcc.exe -Wall -m32 -mwin32 -IC:\cygwin64 -c C:\Users\sangheon\codeblock_test\pipe\main.c -o obj\Debug\main.o
i686-pc-cygwin-g++.exe  -o bin\Debug\pipe.exe obj\Debug\main.o  -m32  
C:\Users\sangheon\codeblock_test\pipe\main.c:13:5: error: conflicting types for 'write'
 int write(int fd,void *buf,unsigned len);
     ^~~~~
In file included from /usr/i686-pc-cygwin/sys-root/usr/include/unistd.h:4:0,
                 from C:\Users\sangheon\codeblock_test\pipe\main.c:3:
/usr/i686-pc-cygwin/sys-root/usr/include/sys/unistd.h:245:25: note: previous declaration of 'write' was here
 _READ_WRITE_RETURN_TYPE write (int __fd, const void *__buf, size_t __nbyte);
                         ^~~~~
C:\Users\sangheon\codeblock_test\pipe\main.c: In function 'main':
C:\Users\sangheon\codeblock_test\pipe\main.c:24:5: warning: 'return' with no value, in function returning non-void
     return;
     ^~~~~~
C:\Users\sangheon\codeblock_test\pipe\main.c:14:5: note: declared here
 int main()
     ^~~~
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 1 warning(s) (0 minute(s), 0 second(s))

它说那个错误:“写”的类型冲突  int write(int fd,void * buf,unsigned len); 我总是使用Windows版本的代码块,并且我知道此源代码是UNIX独有的。因此,我安装了cygwin编译器,并将其选择为代码块的编译器。 但是它无法构建此源代码... 是否有在Windows版本的CodeBlocks中构建UNIX源代码的灵魂?

评论