Hey, I am trying to compile the following code and whenever I try to do so it gives me a series of Undefined Symbol Errors like this:
Undefined first referenced
symbol in file
sDate::print() /var/tmp/ccUL1cIa.o
sDate::tomorrow() /var/tmp/ccUL1cIa.o
sDate::addDays(int) /var/tmp/ccUL1cIa.o
sDate::yesterday() /var/tmp/ccUL1cIa.o
sDate::read() /var/tmp/ccUL1cIa.o
sDate::sDate() /var/tmp/ccUL1cIa.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
There are no warnings. I believe it's a linking problem of some sort but I can't figure out what's wrong for the life of me. The code is only 3 files:
Date.h:
#ifndef DATE_H
#define DATE_H
Blah blah blah, the code for Date.h, just a class declaration; yes there is a semi-colon after the declaration; month, day, year, and the int array mday (which is static and const) are declared private, all member functions are declared public.
#endif
Date.cc:
#include "Date.h"
#include <iostream>
using namespace std;
Blah blah blah, all member functions defined, all of them with sDate:: before the name of the function.
Date_driver.cc:
#include <iostream>
#include "Date.h"
using namespace std;
main() creates an sDate "day" and tests all member functions using it.
I compile using g++ in Unix with the following commands:
g++ -c Date.cc (works)
g++ Date_driver.cc (outputs undefined symbol errors)
When I include Date.cc instead of Date.h in the driver file the compiler doesn't output undefined symbols for all of the member functions, but it outputs an undefined symbol for "mday" (the array declared in the .h).
I cannot figure out what is wrong for the life of me. I have tried like everything. If anyone has any suggestions of something to try I'd appreciate it.