Cocos2dx: dlopen failed: cannot locate symbol "atof" referenced by "libcocos2dcpp.so"
Asked Answered
T

5

5

I am trying to run my cocos2d-x game on android devices, it works perfectly on android 5.0(lollipop), but crashes on lower android versions. I am getting the following error:

02-25 10:41:09.787: E/ResourceType(18090): 0x5ad385b8: Failed to ResTable::remove() cookie = 0x3, not last table. mHeaders.size() = 4. Warning for spontaneous crashes when the garbage collector runs. 02-25 10:41:09.797: E/asset(18090): Error removing runtime skin resource (cookie 0x3) 02-25 10:41:09.797: I/asset(18090): Problem removing all runtime skin resources 02-25 10:41:09.817: D/dalvikvm(18090): Trying to load lib /data/app-lib/com.example.game-2/libcocos2dcpp.so 0x418c9ce8 02-25 10:41:09.817: E/dalvikvm(18090): dlopen("/data/app-lib/com.example.game-2/libcocos2dcpp.so") failed: dlopen failed: cannot locate symbol "atof" referenced by "libcocos2dcpp.so"... 02-25 10:41:09.817: W/dalvikvm(18090): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/example/game/game; 02-25 10:41:09.817: W/dalvikvm(18090): Class init failed in newInstance call (Lcom/example/game/game;) 02-25 10:41:09.817: D/AndroidRuntime(18090): Shutting down VM 02-25 10:41:09.817: W/dalvikvm(18090): threadid=1: thread exiting with uncaught exception (group=0x415af8b0) 02-25 10:41:09.827: E/AndroidRuntime(18090): FATAL EXCEPTION: main 02-25 10:41:09.827: E/AndroidRuntime(18090): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "atof" referenced by "libcocos2dcpp.so"... 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.Runtime.loadLibrary(Runtime.java:361)example 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.System.loadLibrary(System.java:525) 02-25 10:41:09.827: E/AndroidRuntime(18090): at com.example.game.game.(game.java:126) 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.Class.newInstanceImpl(Native Method) 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.Class.newInstance(Class.java:1130) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.Instrumentation.newActivity(Instrumentation.java:1061) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2311) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.ActivityThread.access$600(ActivityThread.java:149) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.os.Handler.dispatchMessage(Handler.java:99) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.os.Looper.loop(Looper.java:137) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.ActivityThread.main(ActivityThread.java:5214) 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.reflect.Method.invokeNative(Native Method) 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.reflect.Method.invoke(Method.java:525) 02-25 10:41:09.827: E/AndroidRuntime(18090): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 02-25 10:41:09.827: E/AndroidRuntime(18090): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 02-25 10:41:09.827: E/AndroidRuntime(18090): at dalvik.system.NativeStart.main(Native Method).

I am using cocos2d-x v2.2.6,Eclipse-Luna and android NDK r10d.

Taveda answered 25/2, 2015 at 5:29 Comment(1)
This solution may help you. Add atof implemention by yourself. https://mcmap.net/q/573049/-cannot-load-library-reloc_library-1285-cannot-locate-39-rand-39Tankersley
H
5

Try adding

APP_PLATFORM := android-19 

as the first line in your Appication.mk

Holcman answered 11/3, 2015 at 20:6 Comment(1)
Thanks, this fixed my problem. I think a slightly better option would be to add the APP_PLATFORM := android-xx , where xx is the minSdkVersion that your app is targeting.Shrill
E
1

Try using android NDK r9d.For cocos2dx ,Android NDK r9d is good to work.

Elisha answered 15/10, 2015 at 5:6 Comment(0)
D
1

(I know this duplicates m0mus's earlier answer in the solution suggested, but I think the fuller explanation helps.)

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.

Have you tried setting this in your Application.mk:

APP_PLATFORM := android-9

This will cause the ndk compiler to build code compatible with older Android versions.

You can also try downgrading your NDK installation to version 10b (this version predates the change where atof was moved from inline to part of libc so avoids the problem entirely).

Dismount answered 14/7, 2016 at 16:26 Comment(0)
G
0

I am Getting it right, my current env is cocos2d-x 3.3, NDKr10d, ADT bundle (update24)

 log("This is A TEst for ATOF ,%f ", std::atof("1.0"));

Try including _GXX_EXPERIMENTAL_CXX0X_ in symbols, leave values empty

Gossett answered 25/2, 2015 at 6:52 Comment(0)
R
0

In Android Studio you have to setup manually the NDK. Go to the local.properties file of your porject and setup the ndk.dir value to the ndk directory.

Ruffin answered 29/9, 2015 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.