What am I doing wrong?

I have been trying to use stb_image.h but I am running into some errors that I don't understand. Can some one help me figure it out.

1
2
3
4
5
6
7
8
9
#define STB_IMAGE_IMPLEMENTATION

#include "../../stb/stb_image.h"

internal void 
LoadSTBImage(char *Filename)
{

}


These are the errors I got:
f:\stb\stb_image.h(4503): error C2220: warning treated as error - no 'object' file generated
f:\stb\stb_image.h(4503): warning C4244: '=': conversion from 'int' to 'stbi__uint16', possible loss of data
f:\stb\stb_image.h(5082): warning C4244: 'initializing': conversion from 'int' to 'stbi__uint16', possible loss of data
f:\stb\stb_image.h(5089): warning C4244: '=': conversion from 'int' to 'stbi_uc', possible loss of data
f:\stb\stb_image.h(5090): warning C4244: '=': conversion from 'int' to 'stbi_uc', possible loss of data
f:\stb\stb_image.h(5091): warning C4244: '=': conversion from 'int' to 'stbi_uc', possible loss of data
win32_handmade.cpp
f:\stb\stb_image.h(4503): error C2220: warning treated as error - no 'object' file generated
f:\stb\stb_image.h(4503): warning C4244: '=': conversion from 'int' to 'stbi__uint16', possible loss of data
f:\stb\stb_image.h(5082): warning C4244: 'initializing': conversion from 'int' to 'stbi__uint16', possible loss of data
f:\stb\stb_image.h(5089): warning C4244: '=': conversion from 'int' to 'stbi_uc', possible loss of data
f:\stb\stb_image.h(5090): warning C4244: '=': conversion from 'int' to 'stbi_uc', possible loss of data
f:\stb\stb_image.h(5091): warning C4244: '=': conversion from 'int' to 'stbi_uc', possible loss of data

Any help would be helpful. Thank you.
So it looks like you're building with the -W4 (warning level 4) and -WX (treat warnings as errors) flags turned on, and stb_image has a few internal warnings, which then get treated as errors by your compiler. They're simple warnings to fix, so they should probably be cleaned up by Sean at some point. In the mean time, you have a couple of options.

You could drop your warning level down to 3, or stop compiling with warnings as errors (This probably isn't what you want to do)

You could disable the warning by adding -wd4244 to your build.

You can fix the warnings by changing these lines in stb_image.h
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
//On line 4503
for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is
//                                           ^^ add this

//On line 5082
stbi__uint16 px = (stbi__uint16)stbi__get16le(s);
//                    ^^ add this

//On lines 5089 to 5091
out[0] = (stbi_uc)((r * 255)/31);
out[1] = (stbi_uc)((g * 255)/31);
out[2] = (stbi_uc)((b * 255)/31);
Thank you. Its working now.
aidanb
They're simple warnings to fix, so they should probably be cleaned up by Sean at some point. In the mean time, you have a couple of options.

Perhaps you could submit a pull request with your fixes to save Sean the effort?