A typical object oriented program will have:
// This will be #include "myfirst.h"
class myfirstClass {
public:
int a_number;
void my_func01();
};
// This would be in the myfirstlib.o library, the implementation
void myfirstClass::my_func01() {
std::cout << "This is in my_func01" << std::endl;
}
// And this of course the main body
#include <iostream>
int main() {
myfirstClass mine;
mine.my_func01();
}
- myfirst.h - the header include file
- myfirstlib.cpp - the implementation, compiled to myfirstlib.o
- myfirst - the compiled (and linked program)
// This will be #include "myfirst.h"
class myfirstClass {
public:
int a_number;
void my_func01();
};
// This would be in the myfirstlib.o library, the implementation
void myfirstClass::my_func01() {
std::cout << "This is in my_func01" << std::endl;
}
// And this of course the main body
#include <iostream>
int main() {
myfirstClass mine;
mine.my_func01();
}
The Makefile when you have headers and libraries
So the Makefile would need entries for this like so:
bin/running : bin/myfirst.o bin/myfirstlib.o
$(CC) -o bin/myfirst bin/myfirst.o bin/myfirstlib.o
bin/myfirstlib.o : src/myfirstlib.cpp include/myfirst.h
$(CC) -c -o bin/myfirstlib.o src/myfirstlib.cpp
bin/myfirst.o : src/myfirst.cpp include/myfirst.h
$(CC) -c -o bin/myfirst.o src/myfirst.cpp
bin/running : bin/myfirst.o bin/myfirstlib.o
$(CC) -o bin/myfirst bin/myfirst.o bin/myfirstlib.o
bin/myfirstlib.o : src/myfirstlib.cpp include/myfirst.h
$(CC) -c -o bin/myfirstlib.o src/myfirstlib.cpp
bin/myfirst.o : src/myfirst.cpp include/myfirst.h
$(CC) -c -o bin/myfirst.o src/myfirst.cpp