Problems with compiling SDL_image for Android

Hi,

I have a small program based on SDL2.0 and it works fine on both linux and
windows. I tried to port it to Android on Linuxmint, but some problems
appeared.

I downloaded SDL2.0 and followed its instructions put my program into
project/jni/src. (Actually, my program only contains one YourSourceHere.c
file) I copied the SDL folder to project/jni/. Then I found SDL folder is
not enough. In that program, I used SDL_image to load images and SDL_ttf to
render text. So I put SDL_image folder and SDL_ttf folder into project/jni/
– they both have Android.mk file in them.

But after I ran ndk-build, error messages appeared.

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:34:21:

error: jpeglib.h: No such file or directory

Seemed like SDL_image cannot find the include files of libjpeg-8d.

I noticed in Android.mk of SDL_image that it would link png and jpeg libs
as static libraries. So I downloaded JPEG v8d and libpng 1.5.7 from their
sites since the packages from
http://www.libsdl.org/projects/SDL_image/were for windows. I extracted
the files and used “./configure” and “make”.
When all the header files SDL_image needed were available, I got new errors:

/home/adolfans/my_android_project/android-project/obj/local/armeabi/objs/SDL_image/IMG_jpg.o:

In function `IMG_InitJPG’:

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_calc_output_dimensions’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_CreateDecompress’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_destroy_decompress’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_finish_decompress’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_read_header’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_read_scanlines’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_resync_to_restart’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_start_decompress’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_std_error’

/home/adolfans/my_android_project/android-project/obj/local/armeabi/objs/SDL_image/IMG_png.o:

In function `IMG_InitPNG’:

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_create_info_struct’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_create_read_struct’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_destroy_read_struct’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_IHDR’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_channels’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_io_ptr’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_PLTE’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_tRNS’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_valid’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_read_image’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_read_info’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_read_update_info’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_expand’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_gray_to_rgb’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_packing’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_read_fn’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_strip_16’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_sig_cmp’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_longjmp_fn’

collect2: ld returned 1 exit status

make: ***

[/home/adolfans/my_android_project/android-project/obj/local/armeabi/libSDL_image.so]
error 1

I’ve searched everywhere and didn’t found any instruction on how to compile
SDL_image with SDL2.0 or SDL1.3 for android. Even the README file of
SDL_image didn’t provide any information on that.

I wonder if SDL_image for android is really available…

If it is available, how to solve these problems? Have I done something
wrong?

BTW, I’m still learning English. I don’t know if I have expressed clearly.
If not, I’ll say sorry for my English.

Anyway, thanks in advance!!!

-Adolfans

Hi,

I have a small program based on SDL2.0 and it works fine on both linux and
windows. I tried to port it to Android on Linuxmint, but some problems
appeared.

I downloaded SDL2.0 and followed its instructions put my program into
project/jni/src. (Actually, my program only contains one YourSourceHere.c
file) I copied the SDL folder to project/jni/. Then I found SDL folder is
not enough. In that program, I used SDL_image to load images and SDL_ttf to
render text. So I put SDL_image folder and SDL_ttf folder into project/jni/
– they both have Android.mk file in them.

But after I ran ndk-build, error messages appeared.

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:34:21:

error: jpeglib.h: No such file or directory

Seemed like SDL_image cannot find the include files of libjpeg-8d.

I noticed in Android.mk of SDL_image that it would link png and jpeg libs
as static libraries. So I downloaded JPEG v8d and libpng 1.5.7 from their
sites since the packages from
http://www.libsdl.org/projects/SDL_image/were for windows. I extracted
the files and used “./configure” and “make”.
When all the header files SDL_image needed were available, I got new errors:

/home/adolfans/my_android_project/android-project/obj/local/armeabi/objs/SDL_image/IMG_jpg.o:

In function `IMG_InitJPG’:

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_calc_output_dimensions’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_CreateDecompress’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_destroy_decompress’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_finish_decompress’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_read_header’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_read_scanlines’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_resync_to_restart’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_start_decompress’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_jpg.c:165:

undefined reference to `jpeg_std_error’

/home/adolfans/my_android_project/android-project/obj/local/armeabi/objs/SDL_image/IMG_png.o:

In function `IMG_InitPNG’:

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_create_info_struct’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_create_read_struct’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_destroy_read_struct’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_IHDR’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_channels’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_io_ptr’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_PLTE’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_tRNS’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_get_valid’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_read_image’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_read_info’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_read_update_info’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_expand’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_gray_to_rgb’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_packing’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_read_fn’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_strip_16’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_sig_cmp’

/home/adolfans/my_android_project/android-project/jni/SDL_image-1.2.12/IMG_png.c:291:

undefined reference to `png_set_longjmp_fn’

collect2: ld returned 1 exit status

make: ***

[/home/adolfans/my_android_project/android-project/obj/local/armeabi/libSDL_image.so]
error 1

I’ve searched everywhere and didn’t found any instruction on how to compile
SDL_image with SDL2.0 or SDL1.3 for android. Even the README file of
SDL_image didn’t provide any information on that.

I wonder if SDL_image for android is really available…

If it is available, how to solve these problems? Have I done something
wrong?

BTW, I’m still learning English. I don’t know if I have expressed clearly.
If not, I’ll say sorry for my English.

Anyway, thanks in advance!!!

-Adolfans

2012/3/27 Adolfans <a.dol.fans at gmail.com>:

I’ve searched everywhere and didn’t found any instruction on how to compile
SDL_image with SDL2.0 or SDL1.3 for android. Even the README file of
SDL_image didn’t provide any information on that.
I wonder if SDL_image for android is really available…

If it is available, how to solve these problems? Have I done something
wrong?

Yes, it is available. If you download the sample Android project
you’ll see it uses SDL_image, with libpng and libjpeg. Compiling them
is not much harder than using the right Android.mk file, which you can
lift directly from said demo project.–
Gabriel.

Thansk Gabriel. You say the sample android project. I’m not sure if you
mean the "android-project.zip " on http://www.libsdl.org/tmp/. Seems like
this package is old and it is based on SDL1.2.
Now I’m trying to get the source code from your Ignifuga Game Engine. I
hope the demo will be helpful.

BTW, do you have any idea on how to get rid of the errors I have posted?
-Adolfans

2012/3/27 Adolfans <a.dol.fans at gmail.com>:

Thansk Gabriel. You say the sample android project. I’m not sure if you mean
the "android-project.zip " on http://www.libsdl.org/tmp/. Seems like this
package is old and it is based on SDL1.2.
Now I’m trying to get the source code from your Ignifuga Game Engine. I hope
the demo will be helpful.

The demo itself seemed to have some issues IIRC, but if you look
inside jni/SDL_image, jni/jpeg, jni/png, etc you’ll see you’ll find
what you need to add those libraries to your own project. The errors
you posted are precisely related to the fact that you are not linking
against libjpeg and libpng.–
Gabriel.

Now the problem is solved.

I had put jpeg, png, freetype into project/jni but they didn’t contain
Android.mk in them. So SDL_image and SDL_ttf couldn’t be compiled correctly
because they couldn’t link the static libraries of jpeg, png and freetype.

I wrote Android.mk files for the three libraries to build static libs. As a
result, the error messages disappeared.

Thanks a lot Gabriel.