How to avoid mulpile definition of 'XXXX' at linking for packaging APK

I’m trying to update GPGS C++ SDK version from 1.1 to 1.2.
When I use 1.1 version of GPGS, it compiles fine.
But after update to 1.2, I got linking error.

c:\myproject\proj.android>build_native.py
The Selected NDK toolchain version was 4.8 !
Android NDK: WARNING:jni/../../cocos2d/cocos/./Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libraries
Android NDK: WARNING:jni/../../cocos2d/cocos/platform/android/Android.mk:cocos2dxandroid_static: LOCAL_LDLIBS is always ignored for static libraries
make.exe: Entering directory `c:/myproject/proj.android'

..... compile sources .....

[armeabi-v7a] StaticLibrary  : libextension.a
[armeabi-v7a] SharedLibrary  : libcocos2dcpp.so
ld.exe: error: jni/../../cocos2d/external/curl/prebuilt/android/armeabi-v7a/libcurl.a(md5_dgst.o): multiple definition of 'MD5_Init'
ld.exe: jni/../../gpg-cpp-sdk/android/lib/c++/armeabi-v7a/libgpg.a: previous definition here
ld.exe: error: jni/../../cocos2d/external/curl/prebuilt/android/armeabi-v7a/libcurl.a(md5_dgst.o): multiple definition of 'MD5_Final'
ld.exe: jni/../../gpg-cpp-sdk/android/lib/c++/armeabi-v7a/libgpg.a: previous definition here
ld.exe: error: jni/../../cocos2d/external/curl/prebuilt/android/armeabi-v7a/libcurl.a(md5_dgst.o): multiple definition of 'MD5_Update'
ld.exe: jni/../../gpg-cpp-sdk/android/lib/c++/armeabi-v7a/libgpg.a: previous definition here
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make.exe: *** [obj/local/armeabi-v7a/libcocos2dcpp.so] Error 1
make.exe: Leaving directory `c:/myproject/proj.android'
Traceback (most recent call last):
  File "c:\myproject\proj.android\build_native.py", line 159, in <module>
    build(opts.ndk_build_param,opts.android_platform,opts.build_mode)
  File "c:\myproject\proj.android\build_native.py", line 146, in build
    do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode)
  File "c:\myproject\proj.android\build_native.py", line 82, in do_build
    raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
Exception: Build dynamic library for project [ c:\myproject\proj.android ] fails!

how can I avoid this error?
I need to use network extension too.

I came up against the same problem in Cocos2d-JS today, and I finally found the solution.
Open frameworks/runtime-src/proj.android/jni/Android.mk and add the line below.

LOCAL_LDFLAGS := -Wl,--allow-multiple-definition

This may also be effective for Cocos2d-x.

1 Like

UPDATE (Cocos2d-x) : --allow-multiple-defination does get past the issue, but in the end the build_native.sh script fails for “unknown option ‘–allow-multiple-defination’” so its back to the drawing board…

It was a red flag when no one had clear instructions how to do this… and it looked like everyone said “start with this google project” and all the cocos2d-x tutorials bailed on including the c++ usage… O.o Which made our use of cocos2d-x on Android more of a pain to maintain than anything.

UPDATE 2 There was a lot more to this to get to a compile and link. I ultimately had to upgrade my GCC to a version that supported the atomic namespace and declare (and fid fix my code) to run in c+11 with an Application.mk:
NDK_TOOLCHAIN_VERSION := 4.8
4.6 did not have the support for it.

This was steps taken get Cocos2d-x project to use GPGS C++ SDK v1.2 (to get around the libcurl name collisions, support the atomic namespace, and do so without using a Google sample project as the project template (keeping it all inside a v2.2.5 xcode project.)

NOTE: it compiles, and initializes, beyond that I have no empirical evidence this is fully baked approach yet. I also do not have it working in iOS (yet), but I don’t think it would have until I updated gcc to support the atomic namespace anyway!


This helped in cocos2d-x, specifically before the static libs are actually added. It didn’t help when I added it at the end of the android.mk file. I have more errors to work through, but this got the “multiple definitions” out of the way.

LOCAL_C_INCLUDES := $(LOCAL_PATH)/…/…/Classes

LOCAL_LDFLAGS := -Wl,–allow-multiple-definition

LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static