[Solved] Undefined reference to rand, atof and etc

I’ve built my game with command cocos run -p android --ap android-21, it works fine, my game successfully started on 2 diffrent devices with android 5.0 and 6.0.1, but when I tried to run it on device with android version 4.3 game was crashed. I’ve tried build app with command: cocos run -p android --ap android-19 but it was failed at compilation time with output message:

[armeabi] StaticLibrary : libbullet.a
[armeabi] StaticLibrary : libcocos2dandroid.a
[armeabi] StaticLibrary : libcpufeatures.a
[armeabi] Gdbserver : [arm-linux-androideabi-4.9] libs/armeabi/gdbserver
[armeabi] Gdbsetup : libs/armeabi/gdb.setup
[armeabi] SharedLibrary : libTheGame.so
C:/projects/TheGame/TheGame/cocos2d/cocos/./2d/CCParticleSystem.cpp:608: error: undefined reference to ‘rand’
C:/projects/TheGame/TheGame/cocos2d/cocos/./platform/CCFileUtils.cpp:275: error: undefined reference to ‘atof’
C:/projects/TheGame/TheGame/cocos2d/cocos/./platform/CCFileUtils.cpp:284: error: undefined reference to ‘atof’
C:/projects/TheGame/TheGame/cocos2d/cocos/./base/CCConsole.cpp:1232: error: undefined reference to ‘srand’
C:/projects/TheGame/TheGame/cocos2d/cocos/./base/CCConsole.cpp:1233: error: undefined reference to ‘rand’
C:/projects/TheGame/TheGame/cocos2d/cocos/./base/CCConsole.cpp:1261: error: undefined reference to ‘srand’
C:/projects/TheGame/TheGame/cocos2d/cocos/./base/CCConsole.cpp:1262: error: undefined reference to ‘rand’
C:/projects/TheGame/TheGame/cocos2d/cocos/./base/ccUtils.cpp:255: error: undefined reference to ‘atof’
C:/projects/TheGame/TheGame/cocos2d/cocos/./base/ccRandom.h:117: error: undefined reference to ‘rand’
C:/projects/TheGame/TheGame/cocos2d/cocos/./2d/CCActionTiledGrid.cpp:278: error: undefined reference to ‘srand’
C:/projects/TheGame/TheGame/cocos2d/cocos/./2d/CCActionTiledGrid.cpp:603: error: undefined reference to ‘srand’
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libTheGame.so] Error 1
make.exe: Leaving directory `C:/projects/TheGame/TheGame/proj.android’
Error running command, return code: 2.

I’ve found topic with similar problem, but it seems wasn’t solved CCConsole.cpp:738: error: undefined reference to ‘rand’

How can I solve this problem?

No one can help?

which cocos version and ndk u use?

rand() -> std::rand()
srand() -> std::srand()
atof() -> std::atof()

or add #include "stdlib.h" to these error files.

I use cocos 3.15.1 and ndk-r10e

I guess you forget to clean up.
Just clean the build folder and recompile with cocos run -p android --ap android-19.
compiling with android-21 or higher makes game crash in some android 4.x or lower.

It is unbelievable, I cleaned bin/, gen/, libs/ folders and build has success. Thanks!