I have a main.cpp including a.h (that has its own a.cpp) a.h includes the header only library "stbi_image.h" as such:
#ifndef STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#endif
(https://github.com/nothings/stb)
*.cpp includes its own *.h with the use of #pragma once
But I still get:
LNK1169 one or more multiply defined symbols found LNK2005 stb-failure reason already defined in a.obj file = main.obj ... and a bunch of others
It seems right to me, but as I understand in this question: Multiple definition and header-only libraries
Maybe I should add inline/static to the stb_image.h function I need ? Am I doing something wrong?
Thanks in advance
// stb_image supports loading HDR images in general, and currently the Radiance. // .HDR file format specifically. You can still load any file through the existing. // interface; if you attempt to load an HDR file, it will be automatically remapped.
stb. h is a (theoretically) portable C utility library, which provides numerous features.
No, you already have a way to declare 'stb_image functions' as static or as extern:
#define STB_IMAGE_STATIC
Image.h:
#ifndef _IMAGE_H_
#define _IMAGE_H_
Class Image.h {
public:
Image() : _imgData(NULL) {}
virtual ~Image();
...
void loadf(...);
...
unsigned char* getData() const { return _imgData; }
protected:
unsigned char* _imgData;
};
#endif
Image.cpp:
#include "Image.h"
#define STB_IMAGE_IMPLEMENTATION // use of stb functions once and for all
#include "stb_image.h"
Image::~Image()
{
if ( _imgData )
stbi_image_free(_imgData);
}
void Image::load(...) {
_imgData = stbi_load(...);
}
main.cpp
#include "Image.h" // as you see, main.cpp do not know anything about stb stuff
int main() {
Image* img = new Image(); // this is my 'wrapper' to stb functions
img->load(...);
myTexture(img->getData(), ...);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With