[英]Header only library doesn't use header guards. How can I use the library in other header files?
I'm working with a header only library ( Nuklear ). 我正在使用标题库( Nuklear )。 I include this in my
main.c
file like so: 我把它包含在我的
main.c
文件中,如下所示:
#define SDL_MAIN_HANDLED
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_IMPLEMENTATION
#define NK_SDL_GL3_IMPLEMENTATION
#include "nuklear.h"
#include "nuklear_sdl_gl3.h"
I want to create a file to house some components and break the code up into smaller chunks. 我想创建一个文件来容纳一些组件并将代码分解成更小的块。 I tried to do this by including
nuklear.h
into one of the component headers but got a re declaration error: 我试图通过将
nuklear.h
包含在其中一个组件头中但是得到了一个重新声明错误来做到这一点:
error: redefinition of 'nk_sdl_shutdown'
I don't know any other way to access the types from nuklear.h
in other header files. 我不知道在其他头文件中从
nuklear.h
访问类型的任何其他方法。 Any help please? 有什么帮助吗?
You can wrap the #include
for that library in another header. 您可以将该库的
#include
包装在另一个标头中。
#ifndef NUKLEAR_INCLUDED
#define NUKLEAR_INCLUDED
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_IMPLEMENTATION
#define NK_SDL_GL3_IMPLEMENTATION
#include "nuklear.h"
#include "nuklear_sdl_gl3.h"
#endif
It looks like it does include header guards now. 现在看来它确实包含了标题保护 。 Try updating the library.
尝试更新库。 If that doesn't work file a bug or, even better, a pull request.
如果这不起作用提出错误,或者更好的是拉取请求。
It's open source software, if you find something wrong you can fix it instead of trying to work around the problem. 它是开源软件,如果你发现错误,你可以修复它,而不是试图解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.