Undefined references

Hello everyone,

For some reason, when I attempt to compile this on Unix and Linux:

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
#include "my_allocator.h"

int main()	
	{
	unsigned int memory_size = 0;
	unsigned int block_size = 0;
	
	printf("Enter the memory size and basic block size (in bytes). Both values must be a power of two.\n");
	printf("Memory size: ");
	scanf("%d", &memory_size);
	while (!PowerOfTwo(memory_size))	// Non-power of two
		{
		printf("\nInvalid number. Please enter a power of two.\n");
		printf("Memory size: ");
		scanf("%d", &memory_size);
		}
	
	printf("\nBasic block size: ");
	scanf("%d", &block_size);
	while (!PowerOfTwo(block_size))	// Non-power of two
		{
		printf("\nInvalid number. Please enter a power of two.\n");
		printf("Basic block size: ");
		scanf("%d", &block_size);
		}
	printf("\n");
	
	init_allocator(block_size, memory_size);
	
	release_allocator();
		
	return 0;
	}




I get this undefined reference error:

/tmp/cc0EFhYP.o(.text+0x186): In function `main':
: undefined reference to `init_allocator(unsigned, unsigned)'
/tmp/cc0EFhYP.o(.text+0x18e): In function `main':
: undefined reference to `release_allocator()'
collect2: ld returned 1 exit status


Even though those functions are declared in "my_allocator.h" (included), and defined in my_allocator.c (also includes my_allocator.h). And I checked: There are no mispellings, and the parameters are valid.

Is there another possible reason for this error?



Best regards,
NewProgrammer
Last edited on
Sounds like you forgot to compile/link my_allocator.c.
What are you typing when you compile?
Ahh, that was it. "g++ *.cpp", even though I'm workign with C files. Silly mistake.

Thanks a bunch, guys.
Topic archived. No new replies allowed.