0

When I try to use stbi to load an image all I get is this error:

1>Renderer.obj : error LNK2005: "void __cdecl stbi__unpremultiply_on_load_thread(int)" (?stbi__unpremultiply_on_load_thread@@YAXH@Z) already defined in LoadFile.obj

1>Main.obj : error LNK2005: "void __cdecl stbi__unpremultiply_on_load_thread(int)" (?stbi__unpremultiply_on_load_thread@@YAXH@Z) already defined in LoadFile.obj

1>Shape.obj : error LNK2005: "void __cdecl stbi__unpremultiply_on_load_thread(int)" (?stbi__unpremultiply_on_load_thread@@YAXH@Z) already defined in LoadFile.obj

1>Texture.obj : error LNK2005: "void __cdecl stbi__unpremultiply_on_load_thread(int)" (?stbi__unpremultiply_on_load_thread@@YAXH@Z) already defined in LoadFile.obj

and I get about 180 of these errors for different functions.

I include the stbi in one header file and I use this define

#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
  • 2
    Do you define `STB_IMAGE_IMPLEMENTATION` in every file that you `#include `, or just in one of your files? – jjramsey Jan 05 '22 at 18:06
  • "I include the header file in one file and I use this define": Is that one file a single `.cpp` file or is it itself a header file included in multiple other files? – user17732522 Jan 05 '22 at 18:08
  • @jjramsey I only `#include ` in one file and only use the define in that same file. – Immanuel Charles Jan 05 '22 at 18:09
  • @user17732522 It is a header file included in multiple files – Immanuel Charles Jan 05 '22 at 18:10
  • Does this answer your question? [Double inclusion and headers only library stbi\_image](https://stackoverflow.com/questions/43348798/double-inclusion-and-headers-only-library-stbi-image) and https://gamedev.stackexchange.com/questions/158106/why-am-i-getting-these-errors-when-including-stb-image-h – user17732522 Jan 05 '22 at 18:13
  • 2
    You must include `STB_IMAGE_IMPLEMENTATION` in only one translation unit. Including it in a header that is included in multiple translation units doesn't satisfy this requirement. – user17732522 Jan 05 '22 at 18:13

1 Answers1

0
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

Put this in stb_image.cpp

pedro_bb7
  • 996
  • 2
  • 8
  • 22