Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you compile just a .h file in a makefile?

Tags:

c++

makefile

g++

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?

like image 779
JDN Avatar asked Apr 11 '12 19:04

JDN


1 Answers

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.

like image 145
Steed Avatar answered Sep 20 '22 11:09

Steed