I have two files. sim.c and devices.c.
Here's the sim.c
...
#include "devices.h"
int main(int argc, char **argv) {
pthread_t *tid;
tid = (pthread_t *) malloc(sizeof(pthread_t) * 3);
// this is where I start the 3 threads located in devices.c
if (pthread_create(&tid[0], NULL, device_one, NULL)) {
exit(1);
}
if (pthread_create(&tid[1], NULL, device_two, NULL)) {
exit(1);
}
if (pthread_create(&tid[2], NULL, device_three, NULL)) {
exit(1);
}
// wait for 3 threads to finish
int i;
for (i = 0; i < 3; i++) {
if (pthread_join(tid[i], NULL)) {
exit(1);
}
}
}
Here's devices.c
...
#include "devices.h"
extern void *device_one(void *arg) {
printf("device one is called\n");
return NULL;
}
extern void *device_two(void *arg) {
printf("device two is called\n");
return NULL;
}
extern void *device_three(void *arg) {
printf("device three is called\n");
return NULL;
}
And here's devices.h
#ifndef DEVICES_H
#define DEVICES_H
extern void *device_one(void *arg);
extern void *device_two(void *arg);
extern void *device_three(void *arg);
However, when I compile, I get 3 errors under sim.c saying
undefined reference to 'device_one'
undefined reference to 'device_two'
undefined reference to 'device_three'