I am starting a course on C++ and am having problems with compiling/linking with OSX 10.5.4 using BBedit for writing and g++ for compiling/linking.
My core program is main.cpp consisting of:
#include <iostream>
using std::cout;
using std::endl;
#include "GradeBook.h"
int main()
{
// create two gradeBook objects
GradeBook gradeBook1( "CS101 Introduction to C++ Programming" );
GradeBook gradeBook2( "CS102 Data Structures in C++" );
// display initial value of courseName for each GradeBoook
cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
<< "\ngradeBook2 created for course: " << gradeBook2.getCourseName()
<< endl;
return 0;
}
and the GradeBook.h file is:
#include <string>
using std::string;
// GradeBook class definition
class GradeBook
{
public:
GradeBook( string name );
void setCourseName( string name );
string getCourseName();
void displayMessage();
private:
string courseName;
};
When I try to compile link with "g++ -Wall main.cp -o Chapter3"
I get the following:
Undefined symbols:
"GradeBook::GradeBook(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
_main in cc2oAZuH.o
_main in cc2oAZuH.o
"GradeBook::getCourseName()", referenced from:
_main in cc2oAZuH.o
_main in cc2oAZuH.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
All of the files are in the same directory and the g++ is run from the same directory. I understand the errors if the "#include "GradeBook.h" were not included in the main.cpp file, but it is. I am very new to this compile/link process, and would appreciate any and all advice to solve my problem.
My core program is main.cpp consisting of:
#include <iostream>
using std::cout;
using std::endl;
#include "GradeBook.h"
int main()
{
// create two gradeBook objects
GradeBook gradeBook1( "CS101 Introduction to C++ Programming" );
GradeBook gradeBook2( "CS102 Data Structures in C++" );
// display initial value of courseName for each GradeBoook
cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
<< "\ngradeBook2 created for course: " << gradeBook2.getCourseName()
<< endl;
return 0;
}
and the GradeBook.h file is:
#include <string>
using std::string;
// GradeBook class definition
class GradeBook
{
public:
GradeBook( string name );
void setCourseName( string name );
string getCourseName();
void displayMessage();
private:
string courseName;
};
When I try to compile link with "g++ -Wall main.cp -o Chapter3"
I get the following:
Undefined symbols:
"GradeBook::GradeBook(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
_main in cc2oAZuH.o
_main in cc2oAZuH.o
"GradeBook::getCourseName()", referenced from:
_main in cc2oAZuH.o
_main in cc2oAZuH.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
All of the files are in the same directory and the g++ is run from the same directory. I understand the errors if the "#include "GradeBook.h" were not included in the main.cpp file, but it is. I am very new to this compile/link process, and would appreciate any and all advice to solve my problem.