Android FAQ 45: undefined reference to & #39; srand & #39;
Ndk 10b ~ 10e has no problem in compiling and using the C random number functions srand and rand,
However, when the program is running, an error similar to the following is reported:
error: undefined reference to 'srand' error: undefined reference to 'rand'
This leaves me puzzled.
I made the following attempts:
1. Some netizens said that my ndk version is too low to use a higher version.
I changed the original 10b to 10e, but the result still failed.
2. Some netizens say they want to replace the cross compiler with a later version. I have updated the version and the result is still not correct.
3. Some netizens say they should not use 64-bit ndk. They should use 32-bit ndk. I downloaded a 32-bit 10e, but I still cannot.
When I was about to give up the crash, foreign netizens mentioned stdlib. h, as if I had seen this header file yesterday.
I tried to add this header file, compile and run it, and pass it!
This may be the adjustment of the bionic library, which is somewhat different from the original C standard library. However, since it's okay, it's worth noting!
#include shooter.h#include
#include
void bubble_sort(int *array,int n) { int i,j,tmp; for(i=0;i
i;j--) { if(array[j-1]>array[j]) { tmp = array[j-1]; array[j-1]=array[j]; array[j]=tmp; } } }}int A(int a) { int n = 10; int i; int array[n]; srand(time(NULL)); for(i=0;i