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.


10 Years
Discussion Span
Last Post by Duoas

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


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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.