我已经用 C 语言构建了一个库,但目前它非常庞大,并且有许多用于不同建议的函数,例如:文件操作、数学函数等。
我想做的是将这个库拆分为所有不同的建议,但如果用户想使用所有可以立即调用它(如果可能的话,我不知道)。
我的库叫做 feg_tools。所以现在我要使用它:
#include "feg_tools.h"
我想要一些我只称之为我需要的东西,例如:
#include "feg_tools/mathematics_functions.h"
#include "feg_tools/file_manipulation.h"
或者如果我需要一切:
#include "feg_tools"
我也不知道如何构建这样的 Makefile。
最佳答案
您需要创建一个名为feg_tools的文件夹,并将所有库的.h
(mathematics_functions.h,file_manipulation.h,...) ,然后您可以按照您在问题中所说的那样使用它们。
要包含洞库,您需要一个包含库的所有 #include
指令的 header ,可能是,
feg_tools.h
#include "feg_tools/mathematics_functions.h"
#include "feg_tools/file_manipulation.h"
...
这里的 feg_tools.h 位于 feg_tools 文件夹之外。
我不知道你是否这样做,机器人你还应该在每个 .h
文件中插入 #ifdef
指令中的内容,如下所示:
#ifdef FEG_TOOLS_XXX
//put here the content
#endif //FEG_TOOLS_XXX
这是为了避免头文件的循环依赖。
关于c - 用 C 语言构建模块化库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49391610/