PDA

View Full Version : Issues with rand() and srand()



atuca
11-01-2014, 08:52 AM
using any combination of 8e/9d/10c NDK with the latest build tools get errors revolving around rand/srand.

Using anything but android:targetSdkVersion="21" gives this error:



BUILD SUCCESSFUL
Total time: 5 seconds
Android NDK: WARNING: APP_PLATFORM android-17 is larger than android:minSdkVersi
on 7 in ./AndroidManifest.xml
[armeabi] Compile++ arm : AppName <= AndroidApp.cpp
[armeabi-v7a] Compile++ arm : AppName <= AndroidApp.cpp
[armeabi] SharedLibrary : libAppName.so
[armeabi-v7a] SharedLibrary : libAppName.so
C:/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/..
/lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:
./obj/local/armeabi-v7a/objs/AppName/__/__/__/shared/util/MiscUtils.o: in functio
n Random(int):jni/../../../shared/util/MiscUtils.cpp:170: error: undefined refer
ence to 'rand'
C:/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/..
/lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:
./obj/local/armeabi-v7a/objs/AppName/__/__/__/shared/util/MiscUtils.o: in functio
n RandomRange(int, int):jni/../../../shared/util/MiscUtils.cpp:176: error: undef
ined reference to 'rand'
C:/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/..
/libC/:gcc//androidarm--ndklinux--r10candroideabi//toolchains4.6//arm.-.linux/-.
androideabi.-/4.6./.prebuilt//.windows.//binarm/-.linux.-/androideabilib//bingcc
//ld.exearm:- linux.-/androideabiobj//4.6local//.armeabi.-/v7a./.objs//.AppName.//
__./.__//arm__-/linuxshared-/androideabiutil//binMiscUtils.o/:ld.exe :in .funct
ion/ objRandomRangeFloat/(localfloat/,armeabi /floatobjs)/:AppNamejni//__./.__//._
_.//shared./.util//sharedMiscUtils.o/:util /inMiscUtils.cpp :function181 :Random
(errorint:) :undefinedjni /reference. .to/ .'.rand/'.
.C/:shared//androidutil-/ndkMiscUtils.cpp-:r10c170/:toolchains /errorarm:- linux
undefined- androideabireference- 4.6to/ prebuilt'/randwindows'/
binC/:./.android/-libndk/-gccr10c//armtoolchains-/linuxarm--androideabilinux/-4.
6androideabi/-.4.6.//prebuilt./.windows//.bin.//....//libarm/-gcclinux/-armandro
ideabi-/linuxbin-/androideabild.exe/:4.6 /../.obj//.local.//armeabi.-.v7a//.objs
.//AppNamearm/-__linux/-__androideabi//__bin//sharedld.exe/:util /.MiscUtils.o/:ob
j /inlocal /functionarmeabi /StringToFloatobjs(/stdAppName:/:__string/ __const/&__
)/:sharedjni//util./.MiscUtils.o/:. .in/ .function. /RandomRangeshared(/intutil,
/ MiscUtils.cppint:)733::jni /error.:. /undefined. .reference/ .to. /'sharedatof
/'util
/CMiscUtils.cpp::/176android:- ndkerror-:r10c /undefinedtoolchains /referencearm
-tolinux -'androideabirand-'4.6
/Cprebuilt://windowsandroid/-binndk/-.r10c.//toolchainslib//armgcc-/linuxarm--an
droideabilinux--4.6androideabi//prebuilt4.6//windows./.bin//....//.lib.//gcc./.a
rm/-armlinux--linuxandroideabi-/androideabi4.6//bin./.ld.exe/:. ..//.obj.//local
./.armeabi/-armv7a-/linuxobjs-/androideabiAppName//bin__//ld.exe__:/ __.//sharedob
j//utillocal//MiscUtils.oarmeabi:/ objsin/ AppNamefunction/ __PopFirstParmStringAs
Float/(__std/:__:/stringshared*/,util /stdMiscUtils.o::: stringin) :functionjni
/RandomRangeFloat.(.float/,. .float/).:.jni//shared./.util//.MiscUtils.cpp.:/370
.:. /error:shared /undefinedutil /referenceMiscUtils.cpp :to181 :' atoferror':
Cundefined: /referenceandroid -tondk -'r10crand/'toolchains
/Carm:-/linuxandroid--androideabindk--4.6r10c//prebuilttoolchains//windowsarm/-b
inlinux/-.androideabi.-/4.6lib//prebuiltgcc//windowsarm/-binlinux/-.androideabi.
//4.6lib//.gcc.//arm.-.linux/-.androideabi.//4.6./../.arm/-.linux.-/androideabi.
/.bin//.ld.exe.:/ arm.-/linuxobj-/androideabilocal//binarmeabi/-ld.exev7a:/ objs
.//AppNameobj//__local//__armeabi//__objs//sharedAppName//util__//TextScanner.o__:/
__in/ sharedfunction/ utilTextScanner/:MiscUtils.o::GetParmFloatFromLine (inint
,function intStringToFloat,( stdstd::::stringstring )const:&jni)/:.jni.//....//
....//.shared.//utilshared//TextScanner.cpputil:/172MiscUtils.cpp:: 733error::
errorundefined: referenceundefined toreference 'toatof ''
atofC':
/Candroid:-/ndkandroid--r10cndk/-toolchainsr10c//armtoolchains-/linuxarm--androi
deabilinux--4.6androideabi/-prebuilt4.6//windowsprebuilt//binwindows//.bin.//.li
b.//gcclib//armgcc-/linuxarm--androideabilinux/-4.6androideabi//.4.6.//....//...
.//....//.arm.-/linuxarm--androideabilinux/-binandroideabi//ld.exebin:/ ld.exe.:
/ obj.//localobj//armeabilocal-/v7aarmeabi//objsobjs//AppNameAppName//____//____//__
__//sharedshared//Bulletutil//UnityBuild_BulletGImpact.oMiscUtils.o:: inin fun
ctionfunction btSoftBodyHelpersPopFirstParmStringAsFloat:(:stdDr aw:(:btSoftBody
string**,, btIDebugDrawstd*:,: stringint))::jnijni//....//....//....//sharedsha
red//utilBullet//MiscUtils.cppBulletSoftBody:/370btSoftBodyHelpers.cpp:: 171erro
r:: errorundefined: referenceundefined toreference 'toatof ''
srandC':
/Candroid:-/ndkandroid--r10cndk/-toolchainsr10c//armtoolchains-/linuxarm--androi
deabilinux--4.6androideabi/-prebuilt4.6//windowsprebuilt//binwindows//.bin.//.li
b.//gcclib//armgcc-/linuxarm--androideabilinux/-4.6androideabi//.4.6.//....//...
.//....//.arm.-/linuxarm--androideabilinux/-binandroideabi//ld.exebin:/ ld.exe.:
/ obj.//localobj//armeabilocal//objsarmeabi/-AppNamev7a//__objs//__AppName//____//sh
ared__//util__//TextScanner.oshared:/ Bulletin/ UnityBuild_BulletGImpact.ofuncti
on: TextScannerin: :functionGetParmFloatFromLine (btSoftBodyHelpersint:,: Drawi
nt(,btSoftBody *std,: :btIDebugDrawstring*),: jniint/).:.jni//....//....//shared
./.util//sharedTextScanner.cpp/:Bullet172/:BulletSoftBody /errorbtSoftBodyHelper
s.cpp:: 176undefined: referenceerror :to undefined' atofreference'
toC :'/randandroid'-
ndkC-:r10c//androidtoolchains-/ndkarm--r10clinux/-toolchainsandroideabi/-arm4.6-
/linuxprebuilt-/androideabiwindows-/4.6bin//prebuilt./.windows//libbin//gcc./.ar
m/-liblinux/-gccandroideabi//arm4.6-/linux.-.androideabi//.4.6.//....//....//.ar
m.-/linux.-.androideabi//armbin-/linuxld.exe-:androideabi /.bin//objld.exe/:loca
l /.armeabi//objobjs//localAppName//armeabi__-/v7a__//objs__//AppNameshared//__Bulle
t//__UnityBuild_BulletGImpact.o/:__ /inshared /functionIrrlicht /btSoftBodyHelpe
rsirrBullet:/:liquidbody.oDraw:( btSoftBodyin* ,function btIDebugDrawILiquidBod
y*:,: affectRigidBodyint()IRigidBody:*jni)/:.jni.//....//....//.shared.//Bullets
hared//BulletSoftBodyIrrlicht//btSoftBodyHelpers.cppirrBullet:/171liquidbody.cpp
:: 162error:: errorundefined: referenceundefined toreference 'tosrand ''
srandC':
/Candroid:-/ndkandroid--r10cndk/-toolchainsr10c//armtoolchains-/linuxarm--androi
deabilinux--4.6androideabi/-prebuilt4.6//windowsprebuilt//binwindows//.bin.//.li
b.//gcclib//armgcc-/linuxarm--androideabilinux/-4.6androideabi//.4.6.//....//...
.//....//.arm.-/linuxarm--androideabilinux/-binandroideabi//ld.exebin:/ ld.exe.:
/ obj.//localobj//armeabilocal//objsarmeabi/-AppNamev7a//__objs//__AppName//____//sh
ared__//Bullet__//UnityBuild_BulletGImpact.oshared:/ androidin/ AndroidUtils.ofu
nction: btSoftBodyHelpersin: :functionDraw (AppResizebtSoftBody(*_JNIEnv,* ,btI
DebugDraw *_jobject,* ,int )int:,jni /int.).:/jni./../../../.shared//.Bullet.//B
ulletSoftBodyshared//btSoftBodyHelpers.cppandroid:/176AndroidUtils.cpp:: 801erro
r:: errorundefined: referenceundefined toreference 'torand ''
srandC':
/android-ndk-r10cc/otoolchainsl/larme-clinuxt-2androideabi:- 4.6l/dprebuilt /rwi
ndowse/tbinu/r.n.e/dlib /gcc1/ arme-xlinuxi-tandroideabi /s4.6t/a.t.u/s.
./../../arm-linux-androideabi/bin/ld.exe: ./obj/mlocala/karmeabie/.objse/xAppName/
e__:/ __/*__*/*shared /[Irrlichto/birrBulletj//liquidbody.ol:o cina lfunction/ a
ILiquidBodyr:m:eaffectRigidBodya(bIRigidBodyi*)-:vjni7/a./.l/i.b.M/y.a.k/ushared
./sIrrlichto/]irrBullet /Eliquidbody.cppr:r162o:r error1:
undefined mreferencea ktoe .'srande'x
eC:: /android*-*ndk*- r10cW/toolchainsa/iarmt-linuxi-nandroideabig- 4.6f/oprebui
ltr/ windowsu/nbinf/i.n.i/slibh/egccd/ armj-olinuxb-sandroideabi./.4.6./..
./../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/AppName/__/_
_/__/shared/android/AndroidUtils.o: in function AppResize(_JNIEnv*, _jobject*, i
nt, int):jni/../../../shared/android/AndroidUtils.cpp:801: error: undefined refe
rence to 'srand'
collect2: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libAppName.so] Error 1
Beeper by Seth A. Robinson - run beeper.exe /? for help

Playing ERROR BEEP SOUND!



Using 21 however:



BUILD SUCCESSFUL
Total time: 5 seconds
Android NDK: WARNING: APP_PLATFORM android-21 is larger than android:minSdkVersi
on 7 in ./AndroidManifest.xml
[armeabi] Compile++ arm : AppName <= AndroidApp.cpp
[armeabi-v7a] Compile++ arm : AppName <= AndroidApp.cpp
[armeabi] SharedLibrary : libAppName.so
[armeabi-v7a] SharedLibrary : libAppName.so
[armeabi] Install : libAppName.so => libs/armeabi/libAppName.so
[armeabi-v7a] Install : libAppName.so => libs/armeabi-v7a/libAppName.so
Buildfile: C:\CompanyNameProjects\AppName\proton\AppName\andr oid\build.xml


Works just fine! It even runs on an Android 5.0 (21) emulator.

This was great until I wanted to test on a friend's real device, which to date our options are 4.4. I can successfully deploy this tested working on 5.0 APK on 2 different emulated android versions (4.4 and 4.1), but they give the follow error after tapping to load them in the emulator to start:

(from logcat)


I/ActivityManager( 379): Start proc com.CompanyName.AppName for activity com.Company
Name.AppName/.Main: pid=1095 uid=10053 gids={50053, 3003, 1028, 1015}
E/gralloc_goldfish( 55): gralloc_alloc: Mismatched usage flags: 1080 x 1920, u
sage b33
W/GraphicBufferAllocator( 55): alloc(1080, 1920, 1, 00000b33, ...) failed -22
(Invalid argument)
E/ ( 55): GraphicBufferAlloc::createGraphicBuffer(w=1080, h=1920) faile
d (Invalid argument), handle=0x0
E/BufferQueue( 55): [ScreenshotSurface] dequeueBuffer: SurfaceComposer::create
GraphicBuffer failed
I/ActivityManager( 379): Config changes=480 {1.0 310mcc260mnc en_US ldltr sw360
dp w598dp h335dp 480dpi nrml land finger qwerty/v/v -nav/h s.8}
D/PhoneStatusBar( 430): mSettingsPanelGravity = 55
D/dalvikvm( 1095): Trying to load lib /data/app-lib/com.CompanyName.AppName-2/libMy
aku.so 0xb1e21390
E/dalvikvm( 1095): dlopen("/data/app-lib/com.CompanyName.AppName-2/libAppName.so") fa
iled: dlopen failed: cannot locate symbol "srand" referenced by "libAppName.so"...

D/AndroidRuntime( 1095): Shutting down VM
W/dalvikvm( 1095): threadid=1: thread exiting with uncaught exception (group=0xb
1accba8)
E/AndroidRuntime( 1095): FATAL EXCEPTION: main
E/AndroidRuntime( 1095): Process: com.CompanyName.AppName, PID: 1095
E/AndroidRuntime( 1095): java.lang.UnsatisfiedLinkError: dlopen failed: cannot l
ocate symbol "srand" referenced by "libAppName.so"...
E/AndroidRuntime( 1095): at java.lang.Runtime.loadLibrary(Runtime.java:36
4)
E/AndroidRuntime( 1095): at java.lang.System.loadLibrary(System.java:526)

E/AndroidRuntime( 1095): at com.CompanyName.AppName.Main.onCreate(Main.java:
45)
E/AndroidRuntime( 1095): at android.app.Activity.performCreate(Activity.j
ava:5231)
E/AndroidRuntime( 1095): at android.app.Instrumentation.callActivityOnCre
ate(Instrumentation.java:1087)
E/AndroidRuntime( 1095): at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2159)
E/AndroidRuntime( 1095): at android.app.ActivityThread.handleLaunchActivi
ty(ActivityThread.java:2245)
E/AndroidRuntime( 1095): at android.app.ActivityThread.access$800(Activit
yThread.java:135)
E/AndroidRuntime( 1095): at android.app.ActivityThread$H.handleMessage(Ac
tivityThread.java:1196)
E/AndroidRuntime( 1095): at android.os.Handler.dispatchMessage(Handler.ja
va:102)
E/AndroidRuntime( 1095): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 1095): at android.app.ActivityThread.main(ActivityThrea
d.java:5017)
E/AndroidRuntime( 1095): at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 1095): at java.lang.reflect.Method.invoke(Method.java:5
15)
E/AndroidRuntime( 1095): at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 1095): at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:595)
E/AndroidRuntime( 1095): at dalvik.system.NativeStart.main(Native Method)

D/dalvikvm( 430): GC_FOR_ALLOC freed 18243K, 27% free 11417K/15568K, paused 167
ms, total 175ms
I/Choreographer( 379): Skipped 53 frames! The application may be doing too muc
h work on its main thread.
W/ActivityManager( 379): Force finishing activity com.CompanyName.AppName/.Main
I/InputReader( 379): Reconfiguring input devices. changes=0x00000004
I/InputReader( 379): Device reconfigured: id=0, name='qwerty2', size 1080x1920,
orientation 1, mode 1, display id 0
I/InputReader( 379): Reconfiguring input devices. changes=0x00000004
I/dalvikvm-heap( 430): Grow heap (frag case) to 14.350MB for 3072016-byte alloc
ation
D/dalvikvm( 430): GC_CONCURRENT freed 931K, 28% free 13486K/18572K, paused 5ms+
65ms, total 230ms
I/Choreographer( 536): Skipped 40 frames! The application may be doing too muc
h work on its main thread.
D/dalvikvm( 430): GC_FOR_ALLOC freed <1K, 28% free 13486K/18572K, paused 101ms,
total 101ms
I/dalvikvm-heap( 430): Grow heap (frag case) to 28.164MB for 15436816-byte allo
cation
D/dalvikvm( 430): GC_CONCURRENT freed 0K, 16% free 28561K/33648K, paused 5ms+7m
s, total 46ms
D/dalvikvm( 430): WAIT_FOR_CONCURRENT_GC blocked 40ms
W/ActivityManager( 379): Activity pause timeout for ActivityRecord{b1ff5a48 u0
com.CompanyName.AppName/.Main t3 f}
I/ActivityManager( 379): Config changes=480 {1.0 310mcc260mnc en_US ldltr sw360
dp w360dp h567dp 480dpi nrml port finger qwerty/v/v -nav/h s.9}
I/InputReader( 379): Reconfiguring input devices. changes=0x00000004
I/InputReader( 379): Device reconfigured: id=0, name='qwerty2', size 1080x1920,
orientation 0, mode 1, display id 0
W/EGL_emulation( 536): eglSurfaceAttrib not implemented
W/WindowManager( 379): Window freeze timeout expired.
W/WindowManager( 379): Force clearing orientation change: Window{b201e9e0 u0 Na
vigationBar}
W/WindowManager( 379): Force clearing orientation change: Window{b208b410 u0 co
m.android.systemui.ImageWallpaper}
I/WindowManager( 379): Screen frozen for +3s568ms due to Window{b201e9e0 u0 Nav
igationBar}
D/dalvikvm( 430): GC_FOR_ALLOC freed 18076K, 33% free 10488K/15568K, paused 44m
s, total 45ms
I/dalvikvm-heap( 430): Grow heap (frag case) to 13.444MB for 3072016-byte alloc
ation
D/dalvikvm( 430): GC_CONCURRENT freed <1K, 28% free 13488K/18572K, paused 37ms+
5ms, total 110ms
D/dalvikvm( 430): WAIT_FOR_CONCURRENT_GC blocked 88ms
D/dalvikvm( 430): GC_FOR_ALLOC freed <1K, 28% free 13488K/18572K, paused 45ms,
total 45ms
I/dalvikvm-heap( 430): Grow heap (frag case) to 28.166MB for 15436816-byte allo
cation
D/dalvikvm( 430): GC_CONCURRENT freed 0K, 16% free 28563K/33648K, paused 5ms+6m
s, total 51ms
D/dalvikvm( 430): WAIT_FOR_CONCURRENT_GC blocked 30ms
D/dalvikvm( 379): GC_EXPLICIT freed 191K, 10% free 9220K/10184K, paused 6ms+19m
s, total 144ms
I/Choreographer( 430): Skipped 352 frames! The application may be doing too mu
ch work on its main thread.
D/PhoneStatusBar( 430): mSettingsPanelGravity = 55
E/WindowManager( 379): Starting window AppWindowToken{b21a3058 token=Token{b20e
81b0 ActivityRecord{b1ff5a48 u0 com.CompanyName.AppName/.Main t3}}} timed out
W/ActivityManager( 379): Activity destroy timeout for ActivityRecord{b1ff5a48 u
0 com.CompanyName.AppName/.Main t3 f}



The error here looks very similar showing "cannot locate symbol "srand" referenced by "libAppName.so""

So while it compiles and even runs on Android 5.0 with the newest tools (which is great), I cant figure out the right combination to get it to work on older versions of Android. Any suggestions? This is basic app built on a copy RTPhysics so I have irrlicht/bullet tied into this build.

Seth
11-09-2014, 11:14 PM
Hmm. I'm still on the older tools but will probably need to upgrade soon. It's this kind of thing that makes me put it off as long as possible, so by the time I upgrade there is more out there to google when I'm trying to fix it. :nuke: :p

atuca
11-16-2014, 07:05 PM
I eventually got it to compile on NDK10c using Android-19/android:targetSdkVersion 19. I wish I knew better what I changed to get it to work, but for anyone in the future, that is a solution to get it to truly work on older devices, sdk 21 still doesn't work on anything except Android 5.0.