Reputation: 519
I have a makefile that creates object files for two classes (and main) and one of those classes is just defined in a .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 says it can't find FileName.o
Do I have to create FileName.cpp in order to get this to compile?
Upvotes: 5
Views: 13083
Reputation: 1300
You are using your class from FileName.h somewhere, aren't you? So at least one of your .cpp files should contain #include "FileName.h"
, and .h's code will be compiled with this .cpp and you needn't compile .h's code separately.
Upvotes: 7
Reputation: 490693
You don't normally attempt to compile a header (.h) file by itself. Including it into an otherwise empty .cpp file will let you compile it and produce a .o file, but it probably won't do much (if any) real good unless you've put things in the header that don't really belong in a header.
Upvotes: 6