nanovg
nanovg copied to clipboard
Separation of header and c files ?
Hi, i can't figure out why nanovg_gl.h contains both definitions and declarations together, if i want to use nvgCreateGLES2 on multiple files so i have to include nanovg_gl.h (with -DNANOVG_GLES2_IMPLEMENTATION) in each files, now the problem occurs, there are so many files which have nvgCreateGLES2 compiled in and they're conflicting with each other in link time. For the moment, i have separated definition and declarations in two separate file, am i correct?
i think the idea is that you only have the implementation in one file, ie get rid of the -DNANOVG_GLES2_IMPLEMENTATION, then pick one cpp file where you do:
#define NANOVG_GLES2_IMPLEMENTATION
#include "nanovg_gl.h"
every else you just include the header. (or... something like that :) )
I agree with one file for implementation, but combining both header and source file will make problems if you need using nvgCreateGLES2 on multiple files say multiple surfaces.
The one file idea is taken from stb libraries [1]. You should have only one file in your project where you define the implementation as @kritzikratzi mentioned.
[1] https://github.com/nothings/stb
Ran into the same problem. Perhaps this should be mentioned in the README?
I am guessing the reason the stb approach is used is so GL lib wrangling is left up to user.
what about using nvgluCreateFramebuffer (in nanovg_gl_utils.h) in multiple files, its impossible with this approach.
Hello,
Sorry to reopen that old issue but I struggle a lot with the same problem.
Has anything changed regarding the inclusion of nanovg_gl.h in several .cpp ? I tried to write in a first .cpp :
#include <nanovg.h> #define NANOVG_GL3_IMPLEMENTATION #include <nanovg_gl.h>
There is only one .cpp file which define that as @kritzikratzi suggests and then in my other .cpp file, I only put :
#include <nanovg.h> #include <nanovg_gl.h>
And this leads to the compile-time error C3861 : ncgCreateGL3 identifier not found from that second .cpp file.
i already tried to fix that by declaring the ncgCreateGL3 function in my file without the definition, but the linker send a LNK2019 : unresolved external symbol for the definition.
Any idea of what is happening ?
Dude, there is no ncgCreateGL3 symbol in nanovg, so this is probably just a typo. Also maybe check #634.
@mulle-nat I mean nvgCreateGL3 it's not a copy-past and I make a mistake when I wrote it here, sorry.
Try putting
#include <nanovg.h>
#define NANOVG_GL3
#include <nanovg_gl.h>
into the second .cpp file, which doesn't define NANOVG_GL3_IMPLEMENTATION but does use nvgCreateGL3. This would solve the C3861 problem. The linker problem is some kind of goof in the setup of your project: e.g. the first .cpp that defines NANOVG_GL3_IMPLEMENTATION isn't really linked.
#define NANOVG_GL3
Thanks for your help! I don't really understand what happened or why adding that definition worked, but it fixed my problem.