I think I still don't get it right. I am either using g++ args the wrong way or the includes:
./c++/:
projects/
cars/
src/ (Step: #1)
Car.h
CarFactory.h
Car.cpp
CarFactory.cpp
bin/ (Step: #2)
Car.o
CarFactory.o
libs/
#empty
tut/
src/ (Step: #3)
Tut.cpp
libs/
#empty
bin/
Tut
libs/
libcars.so
I did the following:
Step #1:
g++ -fPIC -c *.cpp
mv *.cpp ../bin/
Step #2:
g++ -shared -fPIC -o libcars.so *.o
Step #3:
g++ -c Tut.cpp -o ../bin/Tut -L../../../libs/ -lcars
Tut.cpp:3:24: fatal error: CarFactory.h: No such file or directory
compilation terminated.
Tut.cpp:
#include <vector>
#include <iostream>
#include "CarFactory.h"
#include "Car.h"
class Tut {
private:
std::vector<cars::Car> cars;
public:
void runTut(char method) {
this->cars = this->orderCars();
this->testDrive(this->cars);
}
}
void orderCars() {
std::cout << "Ordering cars.. " << std::endl;
cars::CarFactory cf;
int carsToBeBuilt = 10;
for (int i = 0; i < carsToBeBuilt; i++) {
cars::Car car = cf.buildCar();
this->cars.push_back(car);
}
}
void testDrive() {
for (std::vector<cars::Car>::iterator it = this->cars.begin(); it != this->cars.end(); ++it) {
std::cout << " driving: " << it->cars << std::endl; //trying to print the car's mem address as car id.
}
}
};
int main(int argc, char* argv[]) {
Tut t;
t.runTut();
return 0;
}
I guess, I do not have to put a different path into the #include because I tell the compiler where to find the lib that contains the needed objects. It's not a wrong path, it doesn't even compile when the lib is in the same directory.