How do you compile only the .h file in a makefile?

I have a make file that creates object files for two classes (and the main one), and one of these classes is simply defined in the .h file. In my makefile, I have a line that says

FileName.o: FileName.h
  g++ -c FileName.h

but when I try to compile it, it says that it cannot find FileName.o

Do I need to create FileName.cpp to compile?

+3
source share
2 answers

You use your class from FileName.h somewhere, right? Therefore, at least one of your .cpp files must contain #include "FileName.h", and the .h code will be compiled with this .cpp, and you do not need to compile the .h code separately.

+4
source

(.h) . .cpp .o, , , ( ), , .

+4

All Articles