您如何仅在makefile中编译.h文件? [英] How do you compile just a .h file in a makefile?

查看:344
本文介绍了您如何仅在makefile中编译.h文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个makefile,它为两个类(和main)创建目标文件,而这些类之一只是在.h文件中定义的.在我的makefile文件中,有一行写着

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

但是当我尝试编译时,它说找不到FileName.o

but when I try to compile it says it can't find FileName.o

我是否必须创建FileName.cpp才能进行编译?

Do I have to create FileName.cpp in order to get this to compile?

推荐答案

您正在某个地方使用FileName.h中的类,不是吗?因此,您的至少一个.cpp文件应包含#include "FileName.h",并且.h的代码将使用此.cpp进行编译,而您无需分别编译.h的代码.

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.

这篇关于您如何仅在makefile中编译.h文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆