#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include "dummy2.h"
int exit_code=0;
void main(int argc, char *argv[]){
int primero=atoi(argv[1]);
int segundo=atoi(argv[2]);
int fd[2];
pipe(fd);
fd[0]=dummy2_open( );
for (int i=0; i<primero; ++i){
int pid = fork();
if(pid==0){
execlp("./slave", "./slave", argv[2], (char *)NULL);
}
}
int acum=0;
while(waitpid(-1, NULL, 0)>0){
int i=0;
int rem=waitpid(-1, &exit_code, 0);
if(rem==-1){
printf("hi ha hagut un error al slave\n");
exit(-1);
}
else{
acum=rem+acum;
}
}
dummy2_test(acum);
sprintf(buffer, "Els fills han acabat\n");
write(1, buffer, strlen(buffer));
exit(0);
}
after compiling it, he replies with that
/tmp/ccA6uqSF.o: In function
main': master.c:(.text+0x1d2): referencia a
dummy2_open 'undefined master.c :(. text + 0x2a0): reference to 'dummy2_test' without defining collect2: error: ld returned 1 exit status Makefile: 4: failure in the instructions for the 'master' objective make: *** [master] Error 1
The content of dummy2.h
// Function headers for MASTER process
int dummy2_open( );
int dummy2_test( int );
// Function headers for SLAVE process
void dummy2_init( char buff[], int );
int dummy2_comp( char buff[], int );
void dummy2_exit( );
and to compile it use
gcc master.c -o master -L -ldummy