problem with cc

Asked by Avinash

I get the following error messages when i execute this c program.

#include<sys/types.h>
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>

int main()
{
 pid_t childpid;
 int status,wait_val;
 if((childpid=fork())==-1)
 {
 perror("The fork failed");
 exit(1);
 }
 else if(childpid==0)
 {
  printf("This i schild with id : %d\n",getpid());
  printf("The parent id= %d\n",getppid());
 exit(2);
 }
else
 {
 wait_val=wait(&status);
 printf("Return Value of wait system call : %d\n",wait_val);
 printf("This is parent with pid = %d\n",getpid());
 printf("The is child with pid = %d\n",childpid);
}
exit(0);
}

avinash@avinash-laptop:~$ cc prog10b.c
prog10b.c:1:22: error: sys/types.h: No such file or directory
prog10b.c:2:18: error: stdio.h: No such file or directory
prog10b.c:3:19: error: unistd.h: No such file or directory
prog10b.c:4:19: error: stdlib.h: No such file or directory
prog10b.c: In function ‘main’:
prog10b.c:8: error: ‘pid_t’ undeclared (first use in this function)
prog10b.c:8: error: (Each undeclared identifier is reported only once
prog10b.c:8: error: for each function it appears in.)
prog10b.c:8: error: expected ‘;’ before ‘childpid’
prog10b.c:10: error: ‘childpid’ undeclared (first use in this function)
prog10b.c:13: warning: incompatible implicit declaration of built-in function ‘exit’
prog10b.c:17: warning: incompatible implicit declaration of built-in function ‘printf’
prog10b.c:19: warning: incompatible implicit declaration of built-in function ‘exit’
prog10b.c:24: warning: incompatible implicit declaration of built-in function ‘printf’
prog10b.c:28: warning: incompatible implicit declaration of built-in function ‘exit’

PLS HELP.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Gord Allott
Solved:
Last query:
Last reply:
Revision history for this message
Best Gord Allott (gordallott) said :
#1

you need to install the build-essential package
sudo apt-get install build-essential

Revision history for this message
Bhavani Shankar (bhavi) said :
#2

Hello

Install the "build-essential" package from synaptic..(not an internet installation,just pop in the ubuntu cd when its asked.. ;)) which will install packages necessary for compilation of C and C++ programs To debug your programs possibly, GNU Debugger ( " gdb " package) will be useful to you to correct possible errors of programming.

Regards

Bhavani Shankar.

Revision history for this message
Avinash (avighegde) said :
#3

Thanks so much