如何在C ++中将多个头文件导出为单个头文件? [英] How to export multiple header files as a single header file in C++?

查看:215
本文介绍了如何在C ++中将多个头文件导出为单个头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio开发DLL。当前,我有一个头文件: MyProject.h

I'm developing a DLL using Visual Studio. Currently, I have one header file: MyProject.h:

#pragma once

#ifdef MYLIBRARY_EXPORTS
#define MYLIBRARY_API __declspec(dllexport)
#else
#define MYLIBRARY_API __declspec(dllimport)
#endif

#include <map>
#include <string>

extern "C" class MYLIBRARY_API Class1
{
    // some stuff here...
};

extern "C" class MYLIBRARY_API Class2
{
    // some stuff here
};

我将向项目添加更多类,并且我想添加单独的头文件对于每个班级(请告知我是否应该这样做)。但是,最终,我希望将所有内容打包到单个.dll和.lib中,使得客户端只需要包含一个头文件即可。也就是说,客户端项目具有 #include MyProject.h ,本质上是头文件及其实现文件的集合。这可能吗,我该如何实现?谢谢。

I am going to be adding some more classes to the project and I would like to add separate header files for each class (please advise if I should not do that). However, eventually, I want to package all that into a single .dll and .lib in such a way that the client only needs to include a single header file. That is, the client project has #include "MyProject.h" which is essentially a collection of header files with their implmentation files. Is this possible and how can I achieve this? Thanks.

编辑:

具体来说,我想做的就是放入<$ c $ Class1.h 中的c> Class1 和 Class2中的 Class2 .h 并将它们都包含在一个名为 MyLibrary.h 的主头文件中,因此客户端只需要执行 #include MyLibrary.h

To be specific, what I want to do is to put Class1 in Class1.h and Class2 in Class2.h and include both of them in one master header file called MyLibrary.h so that a client only have to do #include "MyLibrary.h".

推荐答案

如果您有多个头文件(例如Ah,Bh等),并且只想向客户端提供包含所有内容的Project.h,然后只需在Project.h中包含所有标头-就像这样:

If you have several header files like A.h, B.h etc and want to give the client just Project.h that includes all, then simply include all the headers in Project.h - like so:

#ifndef MY_PROJECT_H
#define MY_PROJECT_H
#include "A.h"
#include "B.h"
#endif

这篇关于如何在C ++中将多个头文件导出为单个头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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