#[Solved] LINK2005 error when trying to load stb_image.h

1 messages · Page 1 of 1 (latest)

visual cove
#

As the name suggest I get the following error while trying to #define STB_IMAGE_IMPLEMENTATION: LNK2005 stbi_convert_iphone_png_to_rgb already defined in main.obj

I was following the following Vulkan tutorial: https://docs.vulkan.org/tutorial/latest/06_Texture_mapping/00_Images.html#_introduction

I added stb_image.h header file (wrapped in another folder) in my visual studio libraries folder and then included it just like in the tutorial.

Removing #define STB_IMAGE_IMPLEMENTATION appears to remove the errors LINK2005 errors but generates LINK2019 error stating unresolved reference "stbi_load" from "createTextureImage" method

gleaming harness
visual cove
#

So what you are saying is that I should move this define over from Triangle.h to Triangle.cpp ?

gleaming harness
#

Yes. Somewhere before stb_image.h is included.

#

(the GLFW define in your picture is fine there)

visual cove
#

May I ask why that is fine there and the other thing is not ?

gleaming harness
#

#include is a fancy word for "take this file and copy/paste it here".
stb_image.h is a header file that also has all of the function definitions inside of it, if STB_IMAGE_IMPLEMENTATION is defined.
So if you have that defined in a header file, think about what that means. You're copy/pasting the entire contents of stb_image.h every time it's included.

// Camera.h
void MyFunction() {
  DoTheThing();
}

// Camera.cpp
#include "Camera.h"

// TriangleApp.cpp
#include "Camera.h"

Do you understand why this example would be a problem?

visual cove
#

I think I got it

#

So, I included this in both main.cpp and Triangle.cpp

#

Which is a problem becausee you cannot have implementations for same stuff in two different files ?

#

[Solved] LINK2005 error when trying to load stb_image.h

#

Btw, thank you for help, it worked ❤️

proud nimbus