zlib support

zlib support
0.0 0


hi all…

I’m new to the tech so this is probably a naive question. My code uses zlib across android and IOS. I see headers in platform/third_party/win32/zlib and corresponding libzlib.lib in win32/libraries but the version is different from what I’m using on OSX to compress the data and I get an error on uncompress. It would be nice if I could debug the zlib code to see the specifics, but no luck… in fact I don’t see the uncompress.c in the cocos2d-x source tree on github so I’m not sure how the library is getting built.

I suppose i could create my own x-platform build of zlib under external in the same manner as Chipmunk, but this would be work and perhaps there is an easier way.

Any suggestions appreciated!


I also have other bits of custom code that are best put into libraries so if there is documentation about properly extending Cocos2D-X to do this just point me to it. A quick search of the wiki didn’t turn up anything but I may have missed it. If it doesn’t exist please let me know and I’ll figure out how to do it, probably using Chipmunk or Box2D as an example. Maybe this is not the best way but I already have x-platform builds of the code and it isn’t highly OS-specific.


Cocos2d-x depends on lots of 3rd libraries. Compiling these 3rd libraries brings about 50% of porting job of each platform, some of them are very tricky.
To make the framework easier to start with, that’s the reason why I put binaries there.

My suggestion is that,

  1. Start from iOS or windows, add zlib source code into xcode/vs then find the crash point. iOS and Windows have better graphical IDE to work with, it will make your work easier.
  2. Then use the fixed zlib source code on android. You can find documents from android ndk to write the android.mk file for zlib.


I see… where do you think the best place to add the code would be? Sitting next to Chipmunk? If the source/build files for zlib are available maybe they would help. You can see that I am trying very hard to be lazy!


ok… just looking at curl raises more than a few questions. I don’t expect anyone has the time/inclination to field them now, but perhaps it helps.

I see the following directory structure:

                           curl.h etc.          ?? these seem to be generic rather than platform-specific. Why not share them across platforms in a common directory?
                           libcurl.a             ?? why are build products mixed with the source?
                        x86                      ?? what is x86 doing under android?
                  curl.h etc.                  ?? they seem to be exactly the same files mentioned above. They don't seem to be soft links..
               libraries                        ?? isn't curl a library? Why are build products mixed with source?
                  libcurl.a                     ?? i guess this is for IOS since it isn't under a platform-specific subdirectory like those under android above
                                                   ?? where is the IOS-specific build file? Is there one? I'm used to CMakeLists.txt or some makefile variant.
                  curl.h etc.                  ?? seems to be another copy of the same files...
              libraries                        ?? isn't curl a library? Why are build products mixed with source?
                                                  ?? where is the win32-specific build file?

The Android.mk file contains:

 LOCAL_PATH := $(call my-dir)

 include $(CLEAR_VARS)
 LOCAL_MODULE := curl_static_prebuilt
 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libcurl.a

In any case it’s no big deal for now. I think I’ll create a project-specific set of libraries outside the cocos2d-x infrastructure.


The files are organized like this because they are built externally using cmake or some other build system and the devs are just being friendly by bundling them into the cocos distribution instead of requiring us to install the dependencies separately. The drawback to this is that there is needless duplication of files across platforms but I’m sure there are other more pressing matters to take care of. To get through this i just incorporated the files into the build under /libs next to cocos2dx and CocosDenshion. I suspect this adds a second or two to the build time as library source code dependencies are checked for each build even if they did not change (they won’t be 99.999% of the time), but no big deal in this case and it’s simple. I don’t know if this helps anyone… but if I ask a question I generally share the solution.