简体   繁体   English

如何在C中包含标头目录

[英]How include a directory of headers in C

我想知道如何在C程序中包含一个包含几个头的目录,而不是一个一个地包含所有头。

这在C语言中是不可能直接实现的。您必须单独包含标头,或者在makefile中进行某种预处理步骤,以合成包含#include其他标头的标头。

There's no such facility in C. Create a master header file that includes everything that's in that directory, and have your clients include that. C中没有这样的功能。创建一个头文件,其中包含该目录中的所有内容,并让您的客户包括该文件。

A side-note: it's always better to know what exactly you are #include -ing, ie hand-pick needed header files, instead of doing this thing wholesale to avoid name clashes, unexpected macro expansion, circular dependencies, and what not. 旁注:最好总是确切地知道您的#include -ing是什么,即,手动选择所需的头文件,而不是批量执行此操作以避免名称冲突,意外的宏扩展,循环依赖以及不这样做。

You can write an header that individually includes the other headers and then include this header elsewhere. 您可以编写一个标头,该标头单独包含其他标头,然后在其他位置包含此标头。 But an include directive can only include one single header. 但是一个include指令只能包含一个标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM