gorten
25-03-2007, 15:31
ciao a tutti, mi sono affacciato da pochissimo su linux e quindi molto niubbo. Ho installato ubuntu come macchina virtuale su VmWare. Avvio e prendo un programma in c molto semplice per prendere confidenza con questo nuovo SO. Il programmino è molto semplice: fa una fork e poi da 2 msg a video x il padre e per il figlio.
Il problema appare quando cerco di compilare poichè gcc non mi riconosce le librerie. Cosa devo fare?
inserisco il programmino che voglio lanciare e le segnalazioni d'errore:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
pid_t Pid;
int stat_val;
Pid=fork();
switch (Pid) {
case -1:
fprintf(stderr, "fork failed\n");
return(1);
case 0: /* Child */
printf("\nSono il figlio......");
sleep(3);
exit(0);
break;
}
waitpid(Pid,(int *)0,0);
printf("\nSono il padre......");
return(0);
}
e gli errori:
got@virtual-ubuntu:~/Desktop$ gcc -o es5 es5.c
es5.c:9:20: error: stdio.h: No such file or directory
es5.c:10:20: error: stdlib.h: No such file or directory
es5.c:11:20: error: unistd.h: No such file or directory
es5.c:12:20: error: string.h: No such file or directory
es5.c:13:23: error: sys/types.h: No such file or directory
es5.c:14:22: error: sys/stat.h: No such file or directory
es5.c:15:19: error: fcntl.h: No such file or directory
es5.c: In function ‘main’:
es5.c:22: error: ‘pid_t’ undeclared (first use in this function)
es5.c:22: error: (Each undeclared identifier is reported only once
es5.c:22: error: for each function it appears in.)
es5.c:22: error: expected ‘;’ before ‘Pid’
es5.c:25: error: ‘Pid’ undeclared (first use in this function)
es5.c:28: warning: incompatible implicit declaration of built-in function ‘fprintf’
es5.c:28: error: ‘stderr’ undeclared (first use in this function)
es5.c:31: warning: incompatible implicit declaration of built-in function ‘printf’
es5.c:33: warning: incompatible implicit declaration of built-in function ‘exit’
es5.c:40: warning: incompatible implicit declaration of built-in function ‘printf’
got@virtual-ubuntu:~/Desktop$
Il problema appare quando cerco di compilare poichè gcc non mi riconosce le librerie. Cosa devo fare?
inserisco il programmino che voglio lanciare e le segnalazioni d'errore:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
pid_t Pid;
int stat_val;
Pid=fork();
switch (Pid) {
case -1:
fprintf(stderr, "fork failed\n");
return(1);
case 0: /* Child */
printf("\nSono il figlio......");
sleep(3);
exit(0);
break;
}
waitpid(Pid,(int *)0,0);
printf("\nSono il padre......");
return(0);
}
e gli errori:
got@virtual-ubuntu:~/Desktop$ gcc -o es5 es5.c
es5.c:9:20: error: stdio.h: No such file or directory
es5.c:10:20: error: stdlib.h: No such file or directory
es5.c:11:20: error: unistd.h: No such file or directory
es5.c:12:20: error: string.h: No such file or directory
es5.c:13:23: error: sys/types.h: No such file or directory
es5.c:14:22: error: sys/stat.h: No such file or directory
es5.c:15:19: error: fcntl.h: No such file or directory
es5.c: In function ‘main’:
es5.c:22: error: ‘pid_t’ undeclared (first use in this function)
es5.c:22: error: (Each undeclared identifier is reported only once
es5.c:22: error: for each function it appears in.)
es5.c:22: error: expected ‘;’ before ‘Pid’
es5.c:25: error: ‘Pid’ undeclared (first use in this function)
es5.c:28: warning: incompatible implicit declaration of built-in function ‘fprintf’
es5.c:28: error: ‘stderr’ undeclared (first use in this function)
es5.c:31: warning: incompatible implicit declaration of built-in function ‘printf’
es5.c:33: warning: incompatible implicit declaration of built-in function ‘exit’
es5.c:40: warning: incompatible implicit declaration of built-in function ‘printf’
got@virtual-ubuntu:~/Desktop$