Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unresolved external symbol _stbi_load #3

Closed
andrepcg opened this issue Jun 6, 2014 · 4 comments
Closed

unresolved external symbol _stbi_load #3

andrepcg opened this issue Jun 6, 2014 · 4 comments

Comments

@andrepcg
Copy link

andrepcg commented Jun 6, 2014

I'm using Visual Studio and the stb_image.h library.

If I call stbi_load in my program I get the following errors:

Error   3   error LNK2019: unresolved external symbol _stbi_load referenced in function "public: bool __thiscall CubemapTexture::Load(void)" (?Load@CubemapTexture@@QAE_NXZ)    ...\CubemapTexture.obj
Error   40  error LNK2001: unresolved external symbol _stbi_load    ...\Texture.obj
@Nairou
Copy link

Nairou commented Jun 6, 2014

From stb_image.h:

Do this:
#define STB_IMAGE_IMPLEMENTATION
before you include this file in one C or C++ file to create the implementation.

@andrepcg
Copy link
Author

andrepcg commented Jun 6, 2014

I missed that line...

I did that in my Utils.h file. Now I'm trying to access the functions in another file that is including Utils.h but I still get errors:

Error   276 error LNK1169: one or more multiply defined symbols found   ...\3PS.exe
Error   274 error LNK2005: _stbi_zlib_decode_noheader_malloc already defined in 3PS.obj ...\Utils.obj
....

I've checked and the fname.obj are all the files referencing Utils.h

@Nairou
Copy link

Nairou commented Jun 6, 2014

That's because STB_IMAGE_IMPLEMENTATION needs to be defined within a .c or .cpp file, not within a header. When you define STB_IMAGE_IMPLEMENTATION, you are creating the bulk of the stb_image code. You only want that code to exist once, like the code in your own project, which is why it has to be defined within a .c or .cpp file.

@andrepcg
Copy link
Author

andrepcg commented Jun 6, 2014

Thanks, solved it!

@nothings nothings closed this as completed Jun 6, 2014
nothings pushed a commit that referenced this issue Sep 7, 2014
GerHobbelt pushed a commit to GerHobbelt/stb that referenced this issue Mar 21, 2024
* Rename stb_image.c to stb.c

* Update CMakeLists.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants