lvandeve / lodepng

PNG encoder and decoder in C and C++.
zlib License
2.06k stars 421 forks source link

how can I use gcc to create .so file #87

Closed SmileChen007 closed 5 years ago

SmileChen007 commented 5 years ago

Thanks, I use Python, so i use lodepng.c and lodepng.h to create .so file by gcc on ubuntu, then it create liblodepng.so . The order is 'gcc lodepng.c -I ./ -fPIC -shared -o liblodepng.so' but when i use this liblodepng.so, it report a bug, image

The bug is : bash: line 1: 14557 Segmentation fault (core dumped) env "PYTHONUNBUFFERED"="1" "PYTHONPATH"="/tmp/pycharm_project_500:/root/.pycharm_helpers/pycharm_matplotlib_backend" "PYCHARM_HOSTED"="1" "JETBRAINS_REMOTE_RUN"="1" "PYCHARM_MATPLOTLIB_PORT"="52649" "PYTHONIOENCODING"="UTF-8" '/home/ubuntu/env/env_fun/bin/python3.5' '-u' '/tmp/pycharm_project_500/png/test.py'

i don't why, the zip file it contains liblodepng.so liblodepng.zip

lvandeve commented 5 years ago

Thanks for your report,

Is there any way in your setup that you can get a stack trace of the C code that runs?

In C, the signature of lodepng_decode32_file is:

unsigned lodepng_decode32_file(unsigned char* out, unsigned w, unsigned h, const char filename);

Are width and height pointers in your code? If "width = 0" means it's a null pointer, that will cause a crash since it wants to write the width to the unsigned integer it points to. Same also for raw_rgba_pixels where it wants to output a pointer to a a buffer it allocates inside. How are pointers handled in this setup?

Thanks

SmileChen007 commented 5 years ago

ok,thanks,I try another way to solve my problem, I run executable file to handle my png.