himake: hello.o printing.o name.o
g++ -o himake hello.o printing.o name.o
hello.o: hello.cpp
g++ -c hello.cpp
printing.o: printing.cpp
g++ -c printing.cpp
name.o: name.cpp
g++ -c name.cpp
Running the above makefile gives me this error below:
[alex@pcc Dir]$ make g++ -o himake hello.o printing.o name.o
hello.o: In function `main':
hello.cpp:(.text+0xc8): undefined reference to `printHello(std::basic_string, std::allocator >)'
collect2: ld returned 1 exit status
make: *** [himake] Error 1
Files: hello.cpp:
// hello.cpp
// standard library
#include <iostream>
#include <string>
using namespace std;
// user defined header files
#include "name.h"
#include "printing.h"
int main ()
{
string name;
name = getName(); // getName is in name.h
printHello(name); // printHello is in print.h
return 0;
}
name.cpp
// name.cpp
// user defined header files
#include "name.h"
#include "printing.h"
string getName()
{
string name;
printGreeting(); // printGreeting is from print.h
getline(cin, name);
return name;
}
name.h
// name.h
#include <iostream>
using namespace std;
string getName();
printing.cpp
// printing.cpp
// user defined include files
#include "printing.h"
void printGreeting(void)
{
cout << "Your name: ";
return;
}
void printHi (string name)
{
cout << "Hi, " << name << endl;
return;
}
printing.h
// printing.h
#include <iostream>
using namespace std;
void printGreeting();
void printHello(string);