文件清单
$ ls
daemon.cc daemon.h makefile say.cc show.cc
$ cat daemon.h
#ifndef _DAEMON_H_
#define _DAEMON_H_
void show();
void say();
#endif
$ cat daemon.cc
#include "daemon.h"
int main(){
show();
}
$ cat say.cc
#include <iostream>
using namespace std ;
#include <sys/types.h>
#include <unistd.h>
void say(){
cout << "this is from say() \n" << endl;
cout << "this pid = " << getpid() << endl ;
}
$ cat show.cc
#include "daemon.h"
using namespace std ;
#include <iostream>
void show(){
cout << "hello this is from show()" << endl;
say();
}
$ cat makefile
aa: daemon.o show.o say.o
g++ daemon.o show.o say.o -o aa
daemon.o: daemon.cc daemon.h
g++ -c daemon.cc daemon.h
show.o: show.cc daemon.h
g++ -c show.cc daemon.h
say.o: say.cc
g++ -c say.cc
clean:
rm -rf *.o *.gch
$ make
g++ -c daemon.cc daemon.h
g++ -c show.cc daemon.h
g++ -c say.cc
g++ daemon.o show.o say.o -o aa
$ ./aa
hello this is from show()
this is from say()
this pid = 7549
$ make clean
rm -rf *.o *.gch
https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html