Hey everyone,

I'm using Dev-C++ to compile the following program. It's simple but for some reason its not working.

#include <stdio.h>
#include <unistd.h>

int main()
     int n, fd[2], pid;
     const int MAXLINE = 4096;
     char line[MAXLINE];
     if(pipe(fd) < 0) {
        printf("Pipe error");
    if((pid = port()) < 0) {
        printf("Fork error");
    else if(pid > 0){
        write(fd[1], "Hello world\n", 12);
    else {
        n = read(fd[0], line, MAXLINE);
        write(STDOUT_FILENO, line, n);
    return 0;

This is my compile log,

Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Dev-Cpp\Projects\Test\main.c" -o "C:\Dev-Cpp\Projects\Test\main.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
{My directory}\Temp/ccEVcaaa.o(.text+0x65):main.c: undefined reference to `pipe'
{My directory}\Temp/ccEVcaaa.o(.text+0x7a):main.c: undefined reference to `port'
collect2: ld returned 1 exit status

Execution terminated

Could someone help me out and let me know what I am doing wrong? Do I have to run it with some sort of cmd line param's?

Thanks in advance for the help.


You're compiling on a windows box, and windows doesn't do pipe's.

I've no idea what port() is.

That would explain it... thanks a lot. So my only option is to compile things through linux then right?

Here is an example of using pipes in MS-Windows programs. Scroll down a bit and there is some example code.

You typed "port()" but I think you meant fork().

That's an OS-specific call. On Windows you have to use CreateProcess().

If you are just doing homework at home, you can ssh into your school and do it over the internet, or you can download Cygwin or MSys to compile it with the GCC (which is likely the same compiler you are using at school).

I use MSys myself and if you want more info about installing it let me know. (It's relatively easy and doesn't do anything weird to your Windows box.)

Hope this helps.