Reputation: 943
I am trying to add libpng to my iPhone project.
I copied the .c and .h files to their own directory "thirdparty/libpng/" and I included png.h in my texture class:
#ifndef PNG_H
#include "thirdparty/libpng/png.h"
#endif
At this point my project compiles great with no warnings and errors.
Next I tried adding a function to check if a texture is a png, and I get a compile error on png_sig_cmp, even though png.h is included:
#define PNG_BYTES_TO_CHECK 4
int GETexture::CheckIfValidPNGTexture( const char* pTextureName, FILE **ppFp )
{
char buf[PNG_BYTES_TO_CHECK];
/* Open the prospective PNG file. */
if ((*ppFp = fopen(pTextureName, "rb")) == NULL)
return 0;
/* Read in some of the signature bytes */
if (fread(buf, 1, PNG_BYTES_TO_CHECK, *ppFp) != PNG_BYTES_TO_CHECK)
return 0;
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
Return nonzero (true) if they match */
return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK)); // <- COMPILE ERROR
}
The error I get is: No matching function for call to 'png_sig_cmp'
The header is definitely getting included. If I try to type something random in it like "sdfdd" I get a compile error, showing it is parsing that header file.
Any ideas?
Upvotes: 2
Views: 1483
Reputation: 95
I had exactly the same problem once and what helped me was simple casting - because if you look into png.h header file , png_sig_cmp definition :
png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check)
First parameter is png_const_bytep - which is defined as :
PNG_CONST png_byte FAR * png_const_bytep
which translated really as :
const unsigned char*
I would simple typecast :
return(!png_sig_cmp((png_const_bytep)buf, (png_size_t)0, PNG_BYTES_TO_CHECK));
Hope it helps!
Upvotes: 3