I’m trying to read a .png image using libpng.so, in an embedded system using the TI cross compiler. I have a stand-alone program that works properly, but when I put the same code inside a CMake project (created by someone else), I get the following error from “png_read_info(png_ptr, info_ptr);”
libpng error: IHDR: CRC error
followed by a core dump
The cross-compiler environment is the same for the two builds (one works, the other crashes) and the source code is the same (in this area) so I’m left with the build system, Make vs. CMake. It seems like the builds might be linking to different versions of the libpng. In both builds, I use #include “png.h” in the source, expecting to pick up:
../ti_cross_compiler/sysroots/armv7at2hf-neon-linux-gnueabi/usr/include/png.h
which points to:
../ti_cross_compiler/sysroots/armv7at2hf-neon-linux-gnueabi/usr/include/libpng16/png.h
And there is an associated lib:
../ti_cross_compiler/sysroots/armv7at2hf-neon-linux-gnueabi/usr/lib/libpng16.so.16.36.0
which matches the lib on the embedded system.
So my questions are:
Is a lib mismatch the likely reason for the CRC error?
Is there a way to determine what headers /libraries are being used by the compile/link commands?
Here’s the source, which is the basic example code that’s available everywhere, but I need to include it to rule that out as the problem.
void read_png(char *filename)
{
FILE* fp = fopen(filename, "rb");
if (!fp) {
std::cerr << "Error: Could not open the PNG file." << std::endl;
return;
}
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
fclose(fp);
std::cerr << "Error: png_create_read_struct failed." << std::endl;
return;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
fclose(fp);
std::cerr << "Error: png_create_info_struct failed." << std::endl;
return;
}
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, 0);
png_read_info(png_ptr, info_ptr); // <<<<< Causes Core Dump >>>>>
int width = png_get_image_width(png_ptr, info_ptr);
int height = png_get_image_height(png_ptr, info_ptr);
int color_type = png_get_color_type(png_ptr, info_ptr);
int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
printf("%s: height=%d, width=%d, bit_depth=%d, type=%dn", filename, height, width, bit_depth, color_type);
}
For the stand-alone code that works, I can get the info from ‘make -n’ which gives:
arm-linux-gnueabihf-gcc –sysroot=/localtmp_ssd/hvwork/mag_sw/ti_cross_compiler/sysroots/armv7at2hf-neon-linux-gnueabi -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard –sysroot=/localtmp_ssd/hvwork/mag_sw/ti_cross_compiler/sysroots/armv7at2hf-neon-linux-gnueabi -Iinc -Wall -g -Wno-pointer-arith -Wno-format -O2 -lm -lstdc++ -lpng -c -o obj/png_test.o src/png_test.cpp
arm-linux-gnueabihf-gcc –sysroot=/localtmp_ssd/hvwork/mag_sw/ti_cross_compiler/sysroots/armv7at2hf-neon-linux-gnueabi -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard –sysroot=/localtmp_ssd/hvwork/mag_sw/ti_cross_compiler/sysroots/armv7at2hf-neon-linux-gnueabi -Iinc -Wall -g -Wno-pointer-arith -Wno-format -O2 -lm -lstdc++ -lpng -o bin/png_test obj/regio.o obj/png_test.o
But I don’t know how to get this info out of the CMake build system.
Hens Vanderschoot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.