[solved] How to include external libs (zlib) on Android?

ShiVa Plugin Development

[solved] How to include external libs (zlib) on Android?

Postby kaxig » 2012-12-13 19:11

Hello everyone!

I want to include an external library (zlib source) into my plugin and compile for Win (Shiva Editor), Android and iPhone using Shiva Edtior 1.9.2b1 Advanced + UAT 1.4b5. I got it running on Windows but I'm stuck on Android native build with the following error (compressBound, compress2 and uncompress are zlib procedures):

Code: Select all
[exec] SharedLibrary  : libS3DClient.so
[exec] c:/programs/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: MyProject_Android/obj/local/armeabi-v7a/MyPlugin_arm_v7a.a(myplugin.o): in function Callback_myplugin_decompress(int, S3DX::AIVariable const*, S3DX::AIVariable*):myplugin.cpp(.text+0x2660): error: undefined reference to 'uncompress'
[exec] c:/programs/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: MyProject_Android/obj/local/armeabi-v7a/MyPlugin_arm_v7a.a(myplugin.o): in function Callback_myplugin_compress(int, S3DX::AIVariable const*, S3DX::AIVariable*):myplugin.cpp(.text+0x26c8): error: undefined reference to 'compressBound'
[exec] c:/programs/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: MyProject_Android/obj/local/armeabi-v7a/MyPlugin_arm_v7a.a(myplugin.o): in function Callback_myplugin_compress(int, S3DX::AIVariable const*, S3DX::AIVariable*):myplugin.cpp(.text+0x26ec): error: undefined reference to 'compress2'
[exec] collect2: ld returned 1 exit status
[exec] make: *** [obj/local/armeabi-v7a/libS3DClient.so] Error 1
[exec] /cygdrive/c/Programs/android-ndk/build/core/build-binary.mk:390: recipe for target `obj/local/armeabi-v7a/libS3DClient.so' failed
[exec] Result: 2


Apparently the objects are not linked into the archive file when compiling the plugin. I copied the content of the zlib-1.2.7 directory (*.h *.c) into Sources\ and tried the following:

Code: Select all
myplugin.cpp
#include "zlib.h"

MyPlugin.makefile:
SOURCES   = zlib.c    # no rule to make target. I don't understand why because the rules in the makefile should cover them: $(SRCROOT)/%.c
SOURCES   = zlib.h    # plugin compiles, but references not found on native build (see log above)
SOURCES = zutil.c uncompr.c ... adler32.c    # no zlib.c btw. this is suggested by the editor if I use plugin properties -> compiler options -> include paths -> "zlib-1.2.7". however I get "multiple definition of Z_ERR. first defined in zutil.o"


I also tried using the native zlib library from Android:
Code: Select all
myplugin.cpp
#include <zlib.h>

MyPlugin.makefile:
CFLAGS_ARM7 = -I"$(SYSROOT_ARM7)/usr"

Android.mk:
LOCAL_LDLIBS         += -lzlib (or libz)


Any help appreciated! Thanks.
Last edited by kaxig on 2012-12-14 18:06, edited 1 time in total.
kaxig
Senior Boarder
Senior Boarder
 
Posts: 73
Joined: 2010-12-15 12:54

Re: How to include external libs (zlib) on Android?

Postby giggsy » 2012-12-13 19:37

Hi,

maybe this helps: http://www.slegg.net/box2d-shiva-wrapper-compiling-box2d-as-plugin

Section "Precompiled Headers".
I had some trouble too getting box2d to compile for android (as C, not java)
Maybe its the same issues :)
giggsy
Platinum Boarder
Platinum Boarder
 
Posts: 1138
Joined: 2010-06-27 21:17
Location: Austria

Re: How to include external libs (zlib) on Android?

Postby kaxig » 2012-12-14 14:56

I resolved the issue in so far as it now compiles with the native Android zlib. I had to specifiy "-lz" (omitting the "lib") instead of "-llibz".

* compiler can't make target because zlib.c doesn't exists, only zlib.h :oops:
* compiling zlib.h doesn't make any sense of course
* compiling all zlib *.c files the multiple definition errors still persists but I'm pretty sure this is the way to go. here's what the error looks like:

Code: Select all
[exec] c:/programs/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuil
t/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-android
eabi/bin/ld.exe: error: MyProject_Android/obj/local/armeabi-v7a/MyPlugin_Android_arm_v7a.a(zutil.o): multiple definition of 'z_errmsg'
[exec] c:/programs/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuil
t/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-android
eabi/bin/ld.exe: MyProject_Android/obj/local/armeabi-v7a/libS3DClient_Android.a(zutil.o): previous definition here
kaxig
Senior Boarder
Senior Boarder
 
Posts: 73
Joined: 2010-12-15 12:54

Re: How to include external libs (zlib) on Android?

Postby NiCoX » 2012-12-14 15:20

Hi kaxig,

About z_errmsg: this is a conflict with an engine symbol. Weird this has not be reported previously, as some months ago we worked on eliminating such conflicts, renaming all engine side zlib symbols, and looks like we forgot this one. We just fixed it.

If you are compiling your own version of zlib, a workaround is just to rename the symbol as well (eg. z_errmsg ==> my_z_errmsg), there are only 3 occurrences. Let me know.
User avatar
NiCoX
Administrator
Administrator
 
Posts: 5654
Joined: 2007-04-19 18:06
Location: France

Re: How to include external libs (zlib) on Android?

Postby kaxig » 2012-12-14 15:30

Thanks!

This one error was just a snippet btw. Here's a list of all conflicting symbols:
Code: Select all
z_errmsg
zcfree
zcalloc
_tr_init
_tr_tally
_length_code
_dist_code
_tr_align
_tr_stored_block
_tr_flush_block
inflate_table
inflate_copyright
inflate_fast


...I already wondered where zzlib*.o files came from. Maybe renaming them to S3D_ would make that obvious as I assumed it is some weird fancy zlib precompiler stuff.
kaxig
Senior Boarder
Senior Boarder
 
Posts: 73
Joined: 2010-12-15 12:54

Re: How to include external libs (zlib) on Android?

Postby kaxig » 2012-12-14 15:40

Another thing. If zlib is already included in the engine... is there some way to just call it from there? :D
Actually I'm just implementing xml.compress/uncompress
kaxig
Senior Boarder
Senior Boarder
 
Posts: 73
Joined: 2010-12-15 12:54

Re: How to include external libs (zlib) on Android?

Postby NiCoX » 2012-12-14 16:20

Maybe renaming them to S3D_ would make that obvious as I assumed it is some weird fancy zlib precompiler stuff.

We actually made it for exported symbols, and it was working for sure at the time we made it. Anyways we'll also rename the ones you listed.

If zlib is already included in the engine... is there some way to just call it from there?

Engine symbols are currently pandora_zlib_compress and pandora_zlib_uncompress ("Pandora" being the engine internal name). Now, this will only work for statically linked plug-ins (eg. Android, iOS) but not on Windows, WinRT, etc.
User avatar
NiCoX
Administrator
Administrator
 
Posts: 5654
Joined: 2007-04-19 18:06
Location: France

Re: How to include external libs (zlib) on Android?

Postby kaxig » 2012-12-14 17:43

changed symbols in zlib.h and it works! haha, what a dirty hack! :D
kaxig
Senior Boarder
Senior Boarder
 
Posts: 73
Joined: 2010-12-15 12:54

Re: [solved] How to include external libs (zlib) on Android?

Postby akshayhazari » 2017-08-30 07:47

cant get past _dist_code . Am I supposed to change the name to my_dist_code in trees.h
akshayhazari
Fresh Boarder
Fresh Boarder
 
Posts: 1
Joined: 2017-08-30 07:46


Return to C++ Plugins and Frameworks

Who is online

Users browsing this forum: No registered users and 2 guests

cron