APUE page 539 error TELL_WAIT undefined.

Hi,
I've been practising client-server shared memory and the APUE test book gives an example and won't compile.
The errors are:
undefined reference to '_TELL_WAIT'
undefined reference to '_TELL_CHILD'
undefined reference to '_WAIT_CHILD'
undefined reference to '_WAIT_PARENT'
undefined reference to '_TELL_PARENT'.

My code is here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "apue.h"
#include <fcntl.h> 			// Included in C:\cygwin\usr\include.
#include <sys/mman.h>

#define NLOOPS 1000
#define SIZE sizeof(long)	// Size of shared memory area.

static int
update(long *ptr)
{
	return((*ptr)++);		// Return value before increment.
}

int main(void)
{
	int fd, i, counter;
	pid_t pid;
	void *area;
	
	if((fd = open("/dev/zero", O_RDWR)) < 0) printf("Open error.");
	if((area = mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) printf("Mmap error.");
	close(fd);				// Can close /dev/zero now that it's mapped.
	
	TELL_WAIT();
	
	if((pid = fork()) < 0)
	{
		printf("Fork error.");
	}
	else if (pid > 0)		// Parent.
	{
		for(i = 0; i < NLOOPS; i += 2)
		{
			if((counter = update((long *)area)) != i) printf("Parent: expected %d, got %d", i, counter);
			
			TELL_CHILD(pid);
			WAIT_CHILD();
		}
	}
	else					// Child.
	{
		for(i = 1; i < NLOOPS + 1; i += 2)
		{
			WAIT_PARENT();
			
			if((counter = update((long *)area)) != i) printf("Child: expected %d, got %d", i, counter);
			
			TELL_PARENT(getppid());
		}
	}
	
	exit(0);
}


the functions are included in the apue.h file:
1
2
3
4
5
void	TELL_WAIT(void);																/* parent/child from Section 8.9. */
void	TELL_PARENT(pid_t);
void	TELL_CHILD(pid_t);
void	WAIT_PARENT(void);
void	WAIT_CHILD(void);

Last edited on
I'd guess you aren't linking in the library that defines those functions. I'm not familiar with the one you're using, though, so perhaps you should check your reference materials about it.
Please show the command line (or makefile) you've used to compile. It's likely you need to compile the file that implements those functions and link them with your file.

For example "gcc lib/tellwait.c myfile.c -o myfile.exe"

There are too many variations, but the command line you're trying to use will give an idea of how you're setup and what the closest working answer will be.
Thank you for the replies.

I think the library is linked okay, if you're referring to "apue.h"? This header file works on other examples so, the apue.h code is correct.

The command line I am using to compile the example is:
gcc -O2 -o sharedMemoryPage539Figure15.33.exe sharedMemoryPage 539Figure15.33.c

I have found some other online examples which run, after some code adjustments, however I expect the text book to run with less complication than the online examples I have currently ended up having to use.
More out of curiosity know to get the text book example to work.
Topic archived. No new replies allowed.