繁体   English   中英

仅标头的ANSI C库怎么可能?

[英]How is a header only ANSI C library possible?

有一个非常受欢迎的名为nuklear的库, 它既是用ANSI C编写的,也完全是标头的。 但是,每个转换单元中只能有一个函数定义,并且ANSI C没有inline函数,那么该库如何正常工作而没有链接器错误?

从第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 ,则包含实现。

暂无
暂无

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

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