collect2 error ld returned 1 exit status c program with function "wait"

I'm trying to make a simple c program by utility make in terminal it shows this:

root@alireza:~/Documents/gnuc++/3/wait# make
gcc wait.o -o wait
/usr/bin/ld: cannot open output file wait: Is a directory
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
root@alireza:~/Documents/gnuc++/3/wait# gcc -o wait wait.c
/usr/bin/ld: cannot open output file wait: Is a directory
collect2: error: ld returned 1 exit status
root@alireza:~/Documents/gnuc++/3/wait#

As shown above, I manually compiled the wait.c file, but it was an error again (Whether gcc or g++). :(

I don't know if it is compiler problem or I am doing it the wrong way.

I am using Kdevelop IDE and it worked.

wait.c file

 #include<stdio.h>
 #include<stdlib.h>
 #include<sys/wait.h>
 #include<unistd.h>  
 int main() {
     pid_t cpid;
     if (fork()== 0)
         exit(0);           /* terminate child */
     else
         cpid = wait(NULL); /* reaping parent */
     printf("Parent pid = %d\n", getpid());
     printf("Child pid = %d\n", cpid);

     return 0;
}

and

Makefile

 cc=gcc

 all: wait.o 
     $(cc) wait.o -o wait

 wait.o:
     $(cc) -c wait.c -o wait.o

 clean:
     rm -rf *.o wait    clear

What should I do to work with a make or manually compile?

Any help and tips on this are appreciated.

1 answer

  • answered 2017-11-12 19:58 nngmg

    Apparently you have a folder called "wait" in your output directory, try to rename your output to wait.out .