Cocos android c++_static compile error

I tried switching to Cocos with prebuilt framework. It works fine for VS2013 but for android it wont compile. I have narrowed the problem down to using c++_static in my Application.mk like so:
APP_STL := c++_static

I tried this on a brand new Cocos project. I tried with frameworks 3.5 and 3.7, and ndk10d and ndk10e. However it works fine when using cocos2d-x source.

Here is the start of what the compiler spits out:

X:\CocosTest35\proj.android\jni>cocos compile -p android
Running command: compile
Building mode: debug
Android platform not specified, searching a default one...
running: '"C:\android\sdk\tools\android" update project -t android-22 -p X:\CocosTest35\proj.android'

Updated project.properties
Updated local.properties
Updated file X:\CocosTest35\proj.android\proguard-project.txt
building native
NDK build mode: debug
NDK_TOOLCHAIN_VERSION: 4.9
running: '"C:\android\android-ndk-r10e\ndk-build" -C X:\CocosTest35\proj.android -j8 NDK_MODULE_PATH=X:\CocosFrameworks\frameworks/cocos2d-x-3.5;X:\CocosFrameworks\frameworks/cocos2d-x-3.5/cocos;X:\CocosFrameworks\frameworks/cocos2d-x-3.5/external NDK_TOOLCHAIN_VERSION=4.9 NDK_DEBUG=1'

Android NDK: WARNING: APP_PLATFORM android-21 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml
make.exe: Entering directory `X:/CocosTest35/proj.android'
[armeabi] Gdbserver      : [arm-linux-androideabi-4.9] libs/armeabi/gdbserver
[armeabi] Gdbsetup       : libs/armeabi/gdb.setup
[armeabi] Compile++ thumb: cocos2dcpp_shared <= main.cpp
[armeabi] Compile++ thumb: cocos2dcpp_shared <= AppDelegate.cpp
[armeabi] Compile++ thumb: cocos2dcpp_shared <= HelloWorldScene.cpp
[armeabi] Compile thumb  : cpufeatures <= cpu-features.c
[armeabi] StaticLibrary  : libcpufeatures.a
[armeabi] SharedLibrary  : libcocos2dcpp.so
jni/../../Classes/AppDelegate.cpp:30: error: undefined reference to 'cocos2d::GLViewImpl::createWithRect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cocos2d::Rect, float)'
jni/../../Classes/AppDelegate.cpp:42: error: undefined reference to 'cocos2d::FileUtils::addSearchPath(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/AppDelegate.o:AppDelegate.cpp:vtable for AppDelegate: error: undefined reference to 'cocos2d::Application::openURL(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
jni/../../Classes/HelloWorldScene.cpp:34: error: undefined reference to 'cocos2d::CSLoader::createNode(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o:HelloWorldScene.cpp:vtable for HelloWorld: error: undefined reference to 'cocos2d::Node::addChild(cocos2d::Node*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o:HelloWorldScene.cpp:vtable for HelloWorld: error: undefined reference to 'cocos2d::Node::getChildByName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o:HelloWorldScene.cpp:vtable for HelloWorld: error: undefined reference to 'cocos2d::Node::enumerateChildren(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<bool (cocos2d::Node*)>) const'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o:HelloWorldScene.cpp:vtable for HelloWorld: error: undefined reference to 'cocos2d::Node::removeChildByName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o:HelloWorldScene.cpp:vtable for HelloWorld: error: undefined reference to 'cocos2d::Node::setName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o:HelloWorldScene.cpp:vtable for HelloWorld: error: undefined reference to 'cocos2d::Node::removeComponent(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o:HelloWorldScene.cpp:vtable for HelloWorld: error: undefined reference to 'cocos2d::Layer::onTouchesBegan(std::__1::vector<cocos2d::Touch*, std::__1::allocator<cocos2d::Touch*> > const&, cocos2d::Event*)'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o:HelloWorldScene.cpp:vtable for HelloWorld: error: undefined reference to 'cocos2d::Layer::onTouchesMoved(std::__1::vector<cocos2d::Touch*, std::__1::allocator<cocos2d::Touch*> > const&, cocos2d::Event*)'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o:HelloWorldScene.cpp:vtable for HelloWorld: error: undefined reference to 'cocos2d::Layer::onTouchesEnded(std::__1::vector<cocos2d::Touch*, std::__1::allocator<cocos2d::Touch*> > const&, cocos2d::Event*)'
./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o:HelloWorldScene.cpp:vtable for HelloWorld: error: undefined reference to 'cocos2d::Layer::onTouchesCancelled(std::__1::vector<cocos2d::Touch*, std::__1::allocator<cocos2d::Touch*> > const&, cocos2d::Event*)'
X:/CocosFrameworks/frameworks/cocos2d-x-3.5/cocos/editor-support/cocostudio/prebuilt-mk/../../../../prebuilt/android/armeabi/libcocostudio.a(CCActionManagerEx.o):function cocostudio::ActionManagerEx::ActionManagerEx(): error: undefined reference to 'std::__detail::_Prime_rehash_policy::_M_next_bkt(unsigned int) const'
X:/CocosFrameworks/frameworks/cocos2d-x-3.5/cocos/editor-support/cocostudio/prebuilt-mk/../../../../prebuilt/android/armeabi/libcocostudio.a(CCActionManagerEx.o):function std::_Hashtable<std::string, std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> >, std::allocator<std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> > >, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::clear(): error: undefined reference to 'std::basic_strin
g<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
X:/CocosFrameworks/frameworks/cocos2d-x-3.5/cocos/editor-support/cocostudio/prebuilt-mk/../../../../prebuilt/android/armeabi/libcocostudio.a(CCActionManagerEx.o):function std::_Hashtable<std::string, std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> >, std::allocator<std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> > >, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_insert_unique_node(unsigned int, unsigned int, std::_
_detail::_Hash_node<std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> >, true>*): error: undefined reference to 'std::__detail::_Prime_rehash_policy::_M_need_rehash(unsigned int, unsigned int, unsigned int) const'
X:/CocosFrameworks/frameworks/cocos2d-x-3.5/cocos/editor-support/cocostudio/prebuilt-mk/../../../../prebuilt/android/armeabi/libcocostudio.a(CCActionManagerEx.o):function std::_Hashtable<std::string, std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> >, std::allocator<std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> > >, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_insert_unique_node(unsigned int, unsigned int, std::_
_detail::_Hash_node<std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> >, true>*): error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
X:/CocosFrameworks/frameworks/cocos2d-x-3.5/cocos/editor-support/cocostudio/prebuilt-mk/../../../../prebuilt/android/armeabi/libcocostudio.a(CCActionManagerEx.o):function std::__detail::_Map_base<std::string, std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> >, std::allocator<std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> > >, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true>, true>::operator[](std::string const&): error: und
efined reference to 'std::_Hash_bytes(void const*, unsigned int, unsigned int)'
X:/CocosFrameworks/frameworks/cocos2d-x-3.5/cocos/editor-support/cocostudio/prebuilt-mk/../../../../prebuilt/android/armeabi/libcocostudio.a(CCActionManagerEx.o):function std::__detail::_Map_base<std::string, std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> >, std::allocator<std::pair<std::string const, cocos2d::Vector<cocostudio::ActionObject*> > >, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true>, true>::operator[](std::string const&): error: und
efined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)'
X:/CocosFrameworks/frameworks/cocos2d-x-3.5/cocos/editor-support/cocostudio/prebuilt-mk/../../../../prebuilt/android/armeabi/libcocostudio.a(CCActionManagerEx.o):function cocostudio::ActionManagerEx::initWithDictionary(char const*, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&, cocos2d::Ref*): error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'

Anyone have an idea whats going on here?

Bump.

I know I’m not the only one using APL_STL := c++_static to compile for Android, but maybe I’m the only one trying it with the prebuilt framework?

Any insight into this problem would be greatly appreciated. I would really like to switch to using Cocos with prebuilt framework but right now this is the only thing holding me back.

Currently I’ve tried to use
APP_STL := c++_static

for

Cocos2d-x/tools/simulator/frameworks/runtime-src/proj.android/jni/Application.mk

Trying to generate prebuilt libs using command:
cocos gen-libs -p android --ap android-19 --app-abi x86:armeabi-v7a

and got errors while generating prebuilt libs:

error: '::fsetpos' has not been declared
 using ::fsetpos;

[x86] Compile++      : cocos2dx_internal_static <= TGAlib.cpp
<built-in>: In function 'float abs(float)':
<built-in>: warning: conflicts with previous declaration here [-Wattributes]
[x86] Compile++      : cocos2dx_internal_static <= ZipUtils.cpp
In file included from /Volumes/MacData/Android/SDK/ndk-bundle/sources/cxx-stl/llvm-libc++/include/string:440:0,
                 from /Volumes/MacData/Cocos2d-x/cocos/./base/ZipUtils.h:30,
                 from /Volumes/MacData/Cocos2d-x/cocos/./base/ZipUtils.cpp:33:
/Volumes/MacData/Android/SDK/ndk-bundle/sources/cxx-stl/llvm-libc++/include/cstdio:137:9: error: '::fgetpos' has not been declared
 using ::fgetpos;
         ^
/Volumes/MacData/Android/SDK/ndk-bundle/sources/cxx-stl/llvm-libc++/include/cstdio:139:9: error: '::fsetpos' has not been declared
 using ::fsetpos;
         ^

@zhangxm why build for android still using deprecated gcc? Why APP_STL := gnustl_static ?
@slackmoehrle who else also actually can answer this question?
It’s really highly recommended to update cocos2d-x to not deprecated things…
Currently I can’t compile cocos2d-x prebuilt libs for android because of that… but I waned to create a tutorial how to use them… I can’t…
I’m using all latest NDK and android studio 3.0, but tools folder replaced with old one(know solution).

@anon98020523 Let me ask someone to look at this.

I think i mentioned why not using c++_static a few times, can refer to this issue too: https://github.com/cocos2d/cocos2d-x/issues/18286.

Your link is just for issues, which one?
Anyway gnu is bad and deprecated and can be even removed later as I understand.

Sorry, the link is: https://github.com/cocos2d/cocos2d-x/issues/18286. Yep, it will be removed, but c++_static is not stable now.

1 Like

Aha, yes, Gnu will be removed so you should start use static beforw to test and get ready code changes.

@zhangxm also in newnon cocos2d-x repo for SpriteBuilderX we don’t have any problems like in bug you posted.
So thats something with your code. I don’t know what was fixed and when I don’t know.
Anyway - you definitely should use c++_static, thats future and if you don’t get ready for that now, you will be in a past…

1 Like

But i can not use not stable lib in engine, developers will use it in real product. But yep, we should prepare for it, how about creating a new branch named android_c++_static to test it.

And we used it for production games for a long time already.

It can not make sure that it doesn’t have issues.

You are only one person who supporting engine currently?

@slackmoehrle @dumganhar and new new guy are supporting cocos2d-x now.

Edit: other developers mostly focus on Creator, and will sync some bug fix from cocos2d-x-lite to cocos2d-x if needed.

Ok I see… but that’s sadly.

1 Like