Cocos2dx development solves the error of undefined reference to 'atof' and internal compiler error reported under x86 platform

Recently, I encountered two problems when making the cocos2dx engine layer code of the java sdk for the game:
1. The game cannot run on the old device (4.4) after installation, but 6.0 is no problem. The crash information is:
xxx/proj.android/../cocos2d/cocos/./platform/CCFileUtils.cpp:277: error: undefined reference to 'atof'
xxx/proj.android/../cocos2d/cocos/./platform/CCFileUtils.cpp:286: error: undefined reference to 'atof'
xxx/proj.android/../cocos2d/cocos/./base/CCConsole.cpp:1224: error: undefined reference to 'srand'
xxx/proj.android/../cocos2d/cocos/./base/CCConsole.cpp:1225: error: undefined reference to 'rand'
xxx/proj.android/../cocos2d/cocos/./base/CCConsole.cpp:1253: error: undefined reference to 'srand'
xxx/proj.android/../cocos2d/cocos/./base/CCConsole.cpp:1254: error: undefined reference to 'rand'
xxx/proj.android/../cocos2d/cocos/./base/ccUtils.cpp:254: error: undefined reference to 'atof'
xxx/proj.android/../cocos2d/cocos/./base/ccRandom.h:117: error: undefined reference to 'rand'
xxx/Pickle/proj.android/../cocos2d/cocos/./base/ccRandom.h:117: error: undefined reference to 'rand'
xxx/proj.android/../cocos2d/cocos/./2d/CCActionTiledGrid.cpp:280: error: undefined reference to 'srand'
xxx/proj.android/../cocos2d/cocos/./2d/CCActionTiledGrid.cpp:605: error: undefined reference to 'srand'

There are two manifestations. It may be that the .so file is compiled, but it crashes when running on the old device, or the above error message is directly prompted when compiling the .so file. No matter which solution is the same, please set APP_PLATFORM := android-19 (or earlier), because google has put the above functions into the l.cpp file since android-21, and it was placed in the .h file before, while ndk and other The sdk is different, it is forward compatible (Forwards Compatibility), that is, the old version is compatible with the new version, but the new version is not compatible with the old version, we always like to compile with the latest version when compiling with jdk or android sdk, but When compiling ndk, please use the old version to compile. In fact, the ideal state is that the APP_PLATFORM of ndk should be equal to the value of minSdkVersion in the manifest. I have been compiling with android-23 before, which caused this problem; 
someone on stackoverflow explained this:
quote

Google have moved some of the C standard library functions like atof() from being inline functions in header files to normal functions. The latest NDKs will default to building a .so that is only compatible with the latest Android devices that have the atof() function in the device's standard C library (libc.so). This means if you run a library on an older device that has an older version of the C library, you will get an error loading the dll as the expected atof() function will not exist.

If it still doesn't work, you may need to check all the above error files. If any file does not include the header file #include <stdlib.h>, please add it by yourself (I added it).
Well, this problem should be solved. Under armeabi and armeabi-v7a, the .so is compiled normally, and the old device runs normally, but when I compile x86, it fails. This is the second problem to be mentioned below.

2. Failed to compile the so file under the x86 platform, the prompt information is as follows
android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/stl_vector.h:93:14: internal compiler error: in tree_node_structure_for_code, at tree.c:408

First of all, I want to explain my development and compilation environment: MacOS X + clang, and use some new features of c++11, such as lambda expressions, as long as the program runs to the lambda expression, it will crash, and finally it is found that the APP_STL needs to be changed. It is enough to be c++_static, which can compile the x86 architecture without crashing:
#Some functions in stdlib.h (atof, srand, etc) used to be static inlined functions
#before android-21 and start to exist in libc.so from android-21. So to support
#old devices before Android-21, APP_PLATFORM should be set before android-21,
#otherwise, application will crash on old devices
APP_PLATFORM := android-19
# ===================== Which APP_STL to use START====================================
#about C++ Library Support, see https://developer.android.com/ndk/guides/cpp-support.html#cs
#Why use c++_static, see http://discuss.cocos2d-x.org/t/why-gnustl-static/23780
#(1)GNU STL runtime: This runtime is the GNU Standard C++ Library, (libstdc++-v3).
#Its shared library file is named libgnustl_shared.so.
#(2)libc++ runtime: This runtime is an Android port of LLVM libc++. Its shared library file is named libc++_shared.so.
#And our dev environment is MacOS X with clang version:Apple LLVM version 7.3.0 (clang-703.0.31)
#And about LLVM libc++, see http://libcxx.llvm.org/, which says:
#libc++ is a 100% complete C++11 implementation on Apple's OS X.
#LLVM and Clang can self host in C++ and C++11 mode with libc++ on Linux.
#libc++ is also a 100% complete C++14 implementation. A list of new features and changes for C++14 can be found here.
# ===================== Which APP_STL to use END====================================
# Instruct to use the static GNU STL implementation
#APP_STL := gnustl_static
APP_STL := c++_static

#Enable C++11. However, pthread, rtti and exceptions aren’t enabled
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char
APP_LDFLAGS := -latomic
#Define this variable as 4.9 to select that version of the GCC compiler.Define this variable as clang to select the Clang compiler, which is the default value for NDK r13 and later.
#see more:https://developer.android.com/ndk/guides/application_mk.html
#NDK_TOOLCHAIN_VERSION: = clang

#Use the following command to compile:
#cocos run -p android -m release --ap android-19
APP_ABI := armeabi, armeabi-v7a, x86, arm64-v8a

ifeq ($(NDK_DEBUG),1)
  APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
  APP_OPTIM := debug
else
  APP_CPPFLAGS += -DNDEBUG
  APP_OPTIM := release
endif

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326493188&siteId=291194637