Error showing up and no clue what it is referencing: symbol(s) not found for architecture x86_64

Mar 8, 2012 at 12:45am
I'm new to c++ and am using Eclipse on my Mac osX. This error (below) has come up and I have no idea why. Can anyone help? Is there something wrong with my code? Please help, I am a newbie.

error:

Building target: Assignment5_2
Invoking: MacOS X C++ Linker
g++ -o "Assignment5_2" ./assignment5_2.o
Undefined symbols for architecture x86_64:
"createtable()", referenced from:
_main in assignment5_2.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [Assignment5_2] Error 1


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
54
55
#include <iostream>
#include <string>

using namespace std;

struct EmployeeRec
{
	int number;
	string name;
	float rate,
		  hours;
};

void popstruct( EmployeeRec employees[ ] );
void createtable( );

int main()
{
	EmployeeRec employees[6];

	popstruct( employees );
	createtable( );

	return 0;
}

void createtable( EmployeeRec employees[ ] )
{
	cout << "Number" << "\t\t" << "Name" << "\t\t" << "Rate" << "\t\t"
	     << "Hours" << endl
	     << "_____________________________________________________" << endl;

	for( int i = 0; i < 6; i++)
	{
		cout << employees[i].number << "\t\t" << employees[i].name << "\t\t"
	             << employees[i].rate << "\t\t" << employees[i].hours << endl;
	}
}

void popstruct( EmployeeRec employees[ ] )
{
	for(int i = 0; i < 6; i++)
	{
		cout << "For employee " << i+1 << ", please enter" << endl
			 << "Number: ";
		cin >> employees[i].number;
		cout << endl << "Name: ";
		cin >> employees[i].name;
		cout << endl << "Rate: ";
		cin >> employees[i].rate;
		cout << endl << "Hours: ";
		cin >> employees[i].hours;
	}
}
Mar 8, 2012 at 12:48am
You declared createtable() as
void createtable( );

But then, in your function definition, you wrote
void createtable( EmployeeRec employees[ ] )

The declaration on line 15 should match with the function definition...(and then in main(), you're calling it wrong).
Mar 8, 2012 at 12:52am
You have a prototype not matching the function.

1
2
3
4
5
// the prototype 
void createtable( );

// the function
void createtable( EmployeeRec employees[ ] )


if you want a c++ compiler to see them as the same thing they need to be exactly alike. In C++ you can have more than one function with the same name with different definitions and this is the case you created, thus the function isn't seen by the linker.
Mar 8, 2012 at 1:04am
Wow. I feel like an idiot. Thanks for your quick responses guys!
Topic archived. No new replies allowed.