有一个非常流行的名为nuklear的库,它都是用ANSI C编写的,完全是头文件。但是,每个转换单元中只能有一个函数定义,而ANSI C没有inline
函数,那么如果没有链接器错误,该库如何正常工作?
答案 0 :(得分:4)
从第73行开始是关于如何使用此标题的说明:
/// ## Usage
/// This library is self contained in one single header file and can be used either
/// in header only mode or in implementation mode. The header only mode is used
/// by default when included and allows including this header in other headers
/// and does not contain the actual implementation. <br /><br />
///
/// The implementation mode requires to define the preprocessor macro
/// NK_IMPLEMENTATION in *one* .c/.cpp file before #includeing this file, e.g.:
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C
/// #define NK_IMPLEMENTATION
/// #include "nuklear.h"
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
所以通常包含这个头文件只会给你声明。如果您在包含之前#define NK_IMPLEMENTATION
,则包含实施。