Undefined Symbol

I'm working on a project and I keep coming across this error. Any help would be wonderful.

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
void Menu::read_students()
	{
		cout<<"Please input the name of the file you would like to read in:"<<endl;
		string file_name;
		cin>>file_name;
		
		ifstream ist(file_name.c_str());
		if(!ist) 
			cerr<<" Unable to open the file: "<<file_name<<endl;

		vector<int>hw_temp;
		vector<int>test_temp;
		vector<int>q_temp;

		int t_quiz;
		int t_hw;
		int t_test;

		string f_name;
		string l_name;
		string id_temp;
		vector<StudentCourses>stdc_vec;

		while(!ist.eof())
		{
			ist>>f_name>>l_name>>id_temp;

			cout<<id_temp<<" "<<f_name<<" "<<l_name;

			for(int i=0; i<10; ++i)
			{
				ist>>t_quiz;
				q_temp.push_back(t_quiz);
			}
			for(int j=0; j<6; ++j)
			{
				ist>>t_hw;
				hw_temp.push_back(t_hw);
			}
			for(int k=0; k<4; ++k)
			{
				ist>>t_test;
				test_temp.push_back(t_test);
			}
			Student temp_student(f_name, l_name, id_temp);
			Courses temp_courses(q_temp, hw_temp, test_temp);
			StudentCourses s_course(temp_student, temp_courses);
			stdc_vec.push_back(s_course);

		}

		
	}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef _STUDENTCOURSES_H_
#define _STUDENTCOURSES_H_

#include "Student.h"
#include "Courses.h"
#include "std_lib_facilities.h"

class StudentCourses
{
public:
   Student student;
   Courses courses;

   Student get_student() const { return student; }
   StudentCourses() {}
   StudentCourses(Student s, Courses c);
   double get_final_score() const;
   void display() const;
};

#endif 


The error I am getting is:

Undefined first referenced
symbol in file
StudentCourses::StudentCourses(Student, Courses)/var/tmp//cchs2k3B.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
So I attached the StudentCourses.h file and the void function that contains the error.
Probably you didn't include the cpps in your project, so your IDE is not linking them.
Could you be more specific? I have all my header files and cpps in a folder and I am compiling in unix using g++ *.cpp.
It's a linker issue.
It does not found the definition of the student_courses constructor. Student temp_student(f_name, l_name, id_temp);
So check out StudentCourses.cpp
Undefined                                                                first referenced
symbol                                                                    in file
StudentCourses::StudentCourses(Student, Courses)                /var/tmp//cchs2k3B.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
Last edited on
Topic archived. No new replies allowed.