I am working on a school project in C++ and am using our schools unix server to write it as instructed by the professor. I am using vim and g++ to compile.
This project is built off another project, Lab0 which I had no trouble getting to build after some help from the TA, but had to do some weird stuff to get it to build (#include LinkedSortedList.cpp file at the bottom of LinkedSortedList.h). Everyone in the class did this weird stuff with #include .cpp file.
First, here are the files and what #includes they have for Lab0 which is compiling fine:
(Tabs in my make file are not showing up in my post....!)
makefile:
main: *.cpp *.h
g++ -o LSL main.cpp
clean:
rm -f *.o LSL*
Lab0 (The one that builds), is like this:
Files:
main.cpp (NOT Templated):
#include "LinkedSortedList.h"
#include <iostream>
using namespace std;
SortedList.h (Templated):
Nothing
LinkedNode.h (Templated):
#include <iostream>
using namespace std;
#include "LinkedSortedList.cpp" - At the bottom fo this file above the #endif to get the program to compile from what the TA told me to do for lab0 due to the templated class.
LinkedSortedList.cpp (Templated):
Nothing
No problems building and running this project.
Below is lab1 the one I am having trouble with and Lab1 uses all the files from Lab0 just adds Employee.h and Employee.cpp.
#include "LinkedSortedList.cpp" - At the bottom fo this file above the #endif to get the program to compile from what the TA told me to do for lab0 due to the templated class.
LinkedSortedList.cpp (Templated):
Nothing
Employee.h (NOT templated):
#include <iostream>
#include <sstream>
using namespace std;
The fix is actually quite simple. g++ didn't know that it needed to also compile your LinkedSortedList.cpp and Employee.cpp files and link with them. Thus, when it gets around to linking everything, it complains.
How you can tell it that you need to compile it at the same time as main.cpp is by adding LinkedSortedList.cpp and Employee.cpp to the end of your g++ call. Good luck!
Fine print: this isn't a kosher practice for larger projects. For those, you might want to compile each of your files into unlinked object files using separate g++ commands, after which you'd then link them together with one command. For a projects with fewer than five files, though, it's probably still okay.
Also, could you please use [code]/*Your code here!*/[/code] tags for your code? This way you won't lose your tabs. Also, for your program output, you can use [output]Output here.[/output] tags. Thanks!