Need Help--Getting the Apple mach-O linker Error

Hey everyone,

Im new to the programming. Recently I've been practicing my coding following by watching Youtube video. I did exactly like the coding in the video, but I got errors. Please help me to fix that. By the way, I'm using Xcode. The guy in the video uses Visual Studio.

#include <iostream>
#include <string>
#include <vector>

#include "Student.h"

using namespace std;

void fillMyClass(vector<student>&);

void printMyclass(const vector<student>&);

int main()
{
vector<student> myClass;
fillMyClass(myClass);
printMyclass(myClass);

return 0;
}

void fillMyClass(vector<student>& newMyClass)
{
int number;
cout<<"Enter the number of class students: "<<endl;
cin>>number;

string name;
char grade;

for(unsigned int i=0; i<number; i++)
{
cout<<"Enter the student's name: "<<endl;
getline(cin, name);

cout<<"Enter student's grade: "<<endl;
cin>>grade;

student NewStudent(name, grade);
newMyClass.push_back(NewStudent);

}

}

void printMyClass(const vector<student>& newMyclass)
{
unsigned int size=newMyclass.size();
for (unsigned int i=0; i<size; i++) {
cout<<"The student name is: "<<newMyclass[i].getName()<<endl;
cout<<"The student grade is: "<<newMyclass[i].getGrade()<<endl;

}
}

And the Error Messages:

Undefined symbols for architecture x86_64:
"printMyclass(std::__1::vector<student, std::__1::allocator<student> > const&)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It seems like something wrong with the PrintMyClass function. Please Help Me!!!
Last edited on
Welcome to the forum.

Please use code tags around your source code. The tags are in the palette to the right.

It looks like you started with a C project rather than a C++ project. It's not linking with the C++ runtime library. It's probably easier to start again, pay special attention to the kind of project to create; it has to be a C++ project.
Thank you for your rely. However, what I did was c++ project. I double checked. And my complier is Apple LLVM 5.0.
Ok, my mistake.

BTW, I've formatted your code so I can see it.
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
#include <iostream>
#include <string>
#include <vector>

#include "Student.h"

using namespace std;

void fillMyClass(vector<student>&);

void printMyclass(const vector<student>&);

int main()
{
	vector<student> myClass;
	fillMyClass(myClass);
	printMyclass(myClass);

	return 0;
}

void fillMyClass(vector<student>& newMyClass)
{
	int number;
	cout<<"Enter the number of class students: "<<endl;
	cin>>number;

	string name;
	char grade;

	for(unsigned int i=0; i<number; i++)
	{
		cout<<"Enter the student's name: "<<endl;
		getline(cin, name);

		cout<<"Enter student's grade: "<<endl;
		cin>>grade;

		student NewStudent(name, grade);
		newMyClass.push_back(NewStudent);
	}
}

void printMyClass(const vector<student>& newMyclass)
{
	unsigned int size=newMyclass.size();
	for (unsigned int i=0; i<size; i++) {
		cout<<"The student name is: "<<newMyclass[i].getName()<<endl;
		cout<<"The student grade is: "<<newMyclass[i].getGrade()<<endl;
	}
}


You missplelt printMyClass (you spelt it printMyclass in main).
Omg, now works. Thank you so much.. I can't believe i made such a stupid mistake.
It's not stupid. It human nature.
Topic archived. No new replies allowed.