Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cocos2dx_static #715

Closed
wants to merge 2 commits into from
Closed

Add cocos2dx_static #715

wants to merge 2 commits into from

Conversation

folecr
Copy link
Contributor

@folecr folecr commented Feb 8, 2012

Add a cocos2dx_static library.

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

As mentioned in NDK_ROOT/documentation.html.

LOCAL_STATIC_LIBRARIES
The list of static libraries modules (built with BUILD_STATIC_LIBRARY)
that should be linked to this module. This only makes sense in
shared library modules.

So we can not use LOCAL_STATIC_LIBRARIES when building a static library.
I have tried this way, and it failed.
Did you try it?

@folecr
Copy link
Contributor Author

folecr commented Feb 9, 2012

Thanks for reviewing.

Could you send me the command you use to build?
I am using the modules documentation from NDK_ROOT/docs/IMPORT-MODULE.html

I am trying to build with either gnustl_static or stlport_static. My build is successful but I am seeing an error at runtime in libc.

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

I use tests/test.android/build_native.sh to build tests.
And I meet the problem that when I build game_logic_shared module(refer tests/android.mk), it says that:

E:/cocos2d-x/tests/test.android/obj/local/armeabi/libcocos2d.a(CCImage.o): In fu
nction pngReadCallback(png_struct_def*, unsigned char*, unsigned int)': CCImage.cpp:(.text._ZL15pngReadCallbackP14png_struct_defPhj+0xe): undefined refe rence topng_get_io_ptr'
CCImage.cpp:(.text._ZL15pngReadCallbackP14png_struct_defPhj+0x60): undefined ref
erence to `png_error'

There are many other errors.
It seems that it can not link to libpng, libjpeg and libxml2.
I also add

LOCAL_STATIC_LIBRARIES := curl_static_prebuilt
LOCAL_STATIC_LIBRARIES += png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
$(call import-module,cocos2dx/platform/third_party/android/modules/libcurl)
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)

in tests/Android.mk, but can not resolve the problem.

@folecr
Copy link
Contributor Author

folecr commented Feb 9, 2012

I'll check this when I get back - you can dump the symbols from the
libraries to confirm.

On Feb 8, 2012, at 6:25 PM, minggo
reply@reply.github.com
wrote:

I use tests/test.android/build_native.sh to build tests.
And I meet the problem that when I build game_logic_shared module(refer tests/android.mk), it says that:

E:/cocos2d-x/tests/test.android/obj/local/armeabi/libcocos2d.a(CCImage.o): In fu
nction pngReadCallback(png_struct_def*, unsigned char*, unsigned int)': CCImage.cpp:(.text._ZL15pngReadCallbackP14png_struct_defPhj+0xe): undefined refe rence topng_get_io_ptr'
CCImage.cpp:(.text._ZL15pngReadCallbackP14png_struct_defPhj+0x60): undefined ref
erence to `png_error'

There are many other errors.
It seems that it can not link to libpng, libjpeg and libxml2.
I also add

LOCAL_STATIC_LIBRARIES := curl_static_prebuilt
LOCAL_STATIC_LIBRARIES += png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
$(call import-module,cocos2dx/platform/third_party/android/modules/libcurl)
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)

in tests/Android.mk, but can not resolve the problem.


Reply to this email directly or view it on GitHub:
#715 (comment)

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

May be my question is:
cocos2dx is a static library, it dependents some other static libraries: libpng, libjpeg and libxml2.
Some other shared library dependents cocos2dx, then how to write the correct Android.mk?

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

I think I find the method.
I should add

LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_STATIC_LIBRARIES += png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)

in every module that depends cocos2dx.
Is there any good method to do like this?

@folecr
Copy link
Contributor Author

folecr commented Feb 9, 2012

There is a WHOLE_STATIC_LIBRARY option somewhere...

On Feb 8, 2012, at 7:09 PM, minggo
reply@reply.github.com
wrote:

I think I find the method.
I should add

LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_STATIC_LIBRARIES += png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)

in every module that depends cocos2dx.
Is there any good method to do like this?


Reply to this email directly or view it on GitHub:
#715 (comment)

@moadib
Copy link
Contributor

moadib commented Feb 9, 2012

I see that next cocos2d-x update will be pain in the ass for android-platform as previous :\ To many changes that do nothing usefull...

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

I think it is useful, because many developers meet error when building with NDK.
And build cocos2dx as a static lib will remove the error when using dynamic_cast.

@moadib
Copy link
Contributor

moadib commented Feb 9, 2012

I mean this romp with submodules and dynamic_cast. Static linking now strictly necessarily, confirm this. I've spended some time to find reason of app crashing after last update and damned author of "change to dynamic_cast" after found it :)

In my case, application must use LOCAL_WHOLE_STATIC_LIBRARIES to cocos2d-x to prevent jni-functions stripping.

You're must be very careful with such changes. This is reasons for some developers thinking that cocos2d-x not ready yet. Then we all know that it is very good library and ready for production :)

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

Thank you moadib.
I will try LOCAL_WHOLE_STATIC_LIBRARIES to prevent jni-functions stripping.

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

I use LOCAL_WHOLE_STATIC_LIBRARIES in cocos2dx/Android.mk.
But module that dependents cocos2dx should also import libpng, libxml2 and libjpeg also.

@moadib
Copy link
Contributor

moadib commented Feb 9, 2012

I didn't examine module system yet. But for 0.11.0 it is nessesary to move all dependencies from cocos2d-x .mk to application .mk for static linking.

@folecr
Copy link
Contributor Author

folecr commented Feb 9, 2012

Please see my recent updates to the pull request. I've added LOCAL_WHOLE_STATIC_LIBRARIES to the cocos2d-x makefiles.

Here is the NDK only project I am using (no Java files)
https://github.com/folecr/cocosdemo-android-ndk

Makefile used to integrate cocos2d-x is here:
https://github.com/folecr/cocosdemo-android-ndk/blob/master/jni/Android.mk

Note that I am trying to move away from crystax C++ libs and to gnustl from the Android NDK.

I am getting errors from spurious symbols defined in libjpeg :
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(djpeg.o): In function main': /cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/djpeg.c:426: multiple definition ofmain'
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(cjpeg.o):/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/cjpeg.c:495: first defined here
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(jpegtran.o): In function main': /cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/jpegtran.c:370: multiple definition ofmain'
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(cjpeg.o):/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/cjpeg.c:495: first defined here
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(rdjpgcom.o): In function main': /cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/rdjpgcom.c:455: multiple definition ofmain'
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(cjpeg.o):/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/cjpeg.c:495: first defined here
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(wrjpgcom.o): In function main': /cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/wrjpgcom.c:414: multiple definition ofmain'
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(cjpeg.o):/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/cjpeg.c:495: first defined here
collect2: ld returned 1 exit status
make: *** [/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/libnative-activity.so] Error 1

@folecr
Copy link
Contributor Author

folecr commented Feb 9, 2012

My next steps will probaly be to build libjpeg, libpng, libxml2 from source...

@folecr
Copy link
Contributor Author

folecr commented Feb 9, 2012

Please discuss if this is the right direction for the project.

Here are my goals :

  • Use Android supported libs where possible
  • Use an Android recommended makefile where possible, so that other Android developers may use Cocos2D-x easily and correctly
  • Build from source (no binary blobs for cocos2d-x developers)
  • Produce binary blobs for users of cocos2d-x
  • Reduce dependency on Java code... produce an example app using C/C++ code only. (I don't know if this is possible.)

Thanks!

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

We only provide source for developers.
We should support android from level 2.1, so we can not produce an example app using C/C++ code only.

Could you please modify the codes from cocos2d-x(including HelloWorld, tests and cocos2dx), not only for cocos2d-x/cocos2dx. Then our environment will be the same.

We divides game logic into two parts: such as HelloWorld/Classes and HelloWorld/android. All the .cpp files under HelloWorld/Classes are platform-independent. So there are two Android.mk(HelloWorld/Classes/Andorid.mk and HelloWorld/android/jni/helloworld/Android.mk).

Of course we can only have one Android.mk just as previous version: including all HelloWorld/Classes/*.cpp files in HelloWorld/android/jni/helloworld/Android.mk. Then obj files will be put in HelloWorld/android/obj/local, not in HelloWorld/android/obj/local/TARGET_ARCH_ABI.

This can cause error when building multiple targets(armeabi and x86) at the same time. Suppose building armeabi first, x86 second. When building x86, the objs are exist in HelloWorld/android/obj/local, then it will not rebuild files under HelloWorld/Classes. This cause link error, because the objs are arm format.

@folecr
Copy link
Contributor Author

folecr commented Feb 9, 2012

Our goals are not in conflict :)

Use Android supported libs where possible

We both agree? ie, move away from using Crystax C++ libs. Is there any dependency on external libs other than Crystax?

Use an Android recommended makefile where possible, so that other Android developers may use Cocos2D-x easily and correctly

We both agree.

Build from source (no binary blobs for cocos2d-x developers)

We both agree. Further, I think we should build libjpeg, libpng and libxml2 from source also.

Produce binary blobs for users of cocos2d-x

We only provide source for developers.

OK. Agreed. Primary deliverable must be source code.

Reduce dependency on Java code... produce an example app using C/C++ code only. (I don't know if this is possible.)

We should support android from level 2.1, so we can not produce an example app using C/C++ code only.

I think both are possible. ie,

  • If using Android 2.2 Java and JNI layer will be developed and used.
  • Android 2.3 and above I will try to use C/C++ only. I don't think this is possible because of TextInput requirements of Cocos. Also a game will have to use Java anyway. Still, I would personally like a C/C++ only library for a game engine. Again, I don't know if this is possible yet :)

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

I use LOCAL_WHOLE_STATIC_LIBRARIES in other module that dependent cococos2dx and add
LOCAL_STATIC_LIBRARIES := png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)

There is not error, and prevent jni-functions stripping.
I will pull request soon.

@folecr
Copy link
Contributor Author

folecr commented Feb 9, 2012

I will take a look at HelloWorld, classes and the x86 Android build tomorrow.

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

We both agree. Further, I think we should build libjpeg, libpng and libxml2 from source also.

But it will add compile time. I think we can offer source code, but use prebuilt lib as default. Developers can use source code if they want to.

Is there any dependency on external libs other than Crystax?

Because at first, stl is not supported by NDK, so we use Crystax version to build libpng, libjpeg. We should rebuild them. You are appreciated if you can do it for the community.

As far as I know, C++ now can not receive input message.

@minggo
Copy link
Contributor

minggo commented Feb 9, 2012

folecr, moadib

I have pulled a request in #716.
Could you please discuss there?

Now I have to include libpng, libjpeg and so on in every module that dependents cocos2dx.
Could you please optimize it if possible based on my pull request?

And I think this pull request should be closed.
folecr, are you agree with me?

@walzer
Copy link
Contributor

walzer commented Feb 9, 2012

Hi moadib, I think using RTTI is required, otherwise the code would be too fat.
Or do you have any smart resolution instead of RTTI? We can discuss in forum.
Sorry about digress from the topic. Go ahead guys.

@folecr
Copy link
Contributor Author

folecr commented Feb 10, 2012

I have pulled a request in #716. Could you please discuss there?

OK.

And I think this pull request should be closed. folecr, are you agree with me?

Yes. Thanks.

@minggo minggo closed this Feb 10, 2012
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 28, 2014
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 28, 2014
fixed cocos2d#715: make sure selected image is valid
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 29, 2014
angeltown pushed a commit to angeltown/cocos2d-x that referenced this pull request Apr 29, 2014
fixed cocos2d#715: make sure selected image is valid
minggo added a commit that referenced this pull request May 4, 2014
minggo added a commit that referenced this pull request May 4, 2014
fixed #715: make sure selected image is valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants