memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.06k stars 767 forks source link

multiple def errors #633

Closed frutas-fruit closed 2 years ago

frutas-fruit commented 2 years ago

I'm trying to add the nanovg src's to a c++ project. My project currently uses a lib which already has stb_freetype.h inlined in it. But this is causing some multiple def linker errors, as nanovg also depends on these stb libs:

.....//nanovg/src/stb_image.h:4271: multiple definition of `stbi_convert_iphone_png_to_rgb'; CMakeFiles/binary.dir/src/main.cpp.o:main.cpp:(.text+0x1b4c0): first defined here
/usr/bin/ld: lib/nanovg/libnanovg.a(nanovg.c.o): in function `stbi_info':
.....//nanovg/src/stb_image.h:6423: multiple definition of `stbi_info'; CMakeFiles/binary.dir/src/main.cpp.o:main.cpp:(.text+0x1b4d0): first defined here
/usr/bin/ld: lib/nanovg/libnanovg.a(nanovg.c.o): in function `stbi_info_from_file':
.....//nanovg/src/stb_image.h:6433: multiple definition of `stbi_info_from_file'; CMakeFiles/binary.dir/src/main.cpp.o:main.cpp:(.text+0x1b610): first defined here
/usr/bin/ld: lib/nanovg/libnanovg.a(nanovg.c.o): in function `stbi_info_from_memory':
.....//nanovg/src/stb_image.h:6445: multiple definition of `stbi_info_from_memory'; CMakeFiles/binary.dir/src/main.cpp.o:main.cpp:(.text+0x1b720): first defined here
/usr/bin/ld: lib/nanovg/libnanovg.a(nanovg.c.o): in function `stbi_info_from_callbacks':

Any ideas of a clean solution to this issue?

frutas-fruit commented 2 years ago

FYI I am also including these headers once in my project:

#include <nanovg.h>
#define NANOVG_GL3_IMPLEMENTATION
#include <nanovg_gl.h>

And I have not explicitly defined any stb headers anywhere in my project

BusyStudent commented 2 years ago

Did you define STB_IMAGE_IMPLEMENTATION in your project? It has already defined in nanovg.c So you can try to remove it from nanovg.c It should work

Or try add STB_IMAGE_STATIC in nanovg.c

frutas-fruit commented 2 years ago

It has already defined in nanovg.c So you can try to remove it from nanovg.c It should work

Awesome, yeah commented out STB_IMAGE_IMPLEMENTATION and STB_TRUETYPE_IMPLEMENTATION and it works well now! Cheers!