mex c compile using arc4random_uniform gets undefined reference to `arc4random_uniform' collect2.exe: error: ld returned 1 exit status

I am trying to install SPIKY on Matlab 2019b which has as part of the SPIKY install the mex script:
mex -Dchar16_t=uint16_T SPIKE_order_surro_MEX.c
The program
SPIKE_order_surro_MEX.c
contains the following:
while (sc<num_swaps) {
brk=0;
coin=arc4random_uniform(num_coins)+1; // get random integer
The compile generates the following error:
Building with 'MinGW64 Compiler (C)'
.
Error using mex
C:\Users\RobLe\AppData\Local\Temp\mex_57607468677249_25364\SPIKE_order_surro_MEX.obj:SPIKE_order_surro_MEX.c:(.text+0x1d0): undefined reference to
`arc4random_uniform'
collect2.exe: error: ld returned 1 exit status
Error in SPIKY_compile_MEX (line 27)
mex -Dchar16_t=uint16_T SPIKE_order_surro_MEX.c
Any idea how I fix this ?
Thanks

6 commentaires

What is SPIKY? Can you provide a link to this software package? Did you contact the authors already?
Jan, Thanks for getting back. SPIKY is code for analysis of neuronal spike trains. The download page is here http://wwwold.fi.isc.cnr.it/users/thomas.kreuz/Source-Code/SPIKY.html
I contacted them and they suggested changing
// coin=arc4random_uniform(num_coins)+1; // gets random integer between 1 and num_coins
to
coin=arc4random_uniform % num_coins; // gets random integer between 0 and num_coins-1
coin = coin +1; // increment by 1
which produced a similar error. For some reason the compiler on my machine is not able to find
arc4random_uniform
They also suggested using arc4random instead of arc4random_uniform which again prodces a similar error.
Can you find the functions arc4random or arc4random_uniform anywhere in your source code?
e.g
coin=arc4random % num_coins; // gets random integer between 0 and num_coins-1
coin = coin +1; // increment by 1
this source code line is in the module SPIKE_order_surro_MEX.c
the package writer got back to me and suggested the following fix. The problem is I am using Windows 10 and not unix/linux :
Please find the solution below.
First, they need to install the bsd library:
Open the terminal Ctrl+Alt+T
(optionally run the sudo apt-get update)
sudo apt-get install libbsd-dev
Second, they need to add it to our code (SPIKE_order_surro_MEX.c): (they could use MATLAB editor)
#include <bsd/stdlib.h>
I have added it after #include <string.h>
Finally, they need to pass the -lbsd to the mex compiler
mex -lbsd SPIKE_order_surro_MEX.c
I have installed Ubuntu 18.04 this morning on my hyper-v virtual machine. I downloaded SPIKY, installed GCC. And with those 3 steps it works.
Let me know if they still have problems,
Cheers,
n.

Connectez-vous pour commenter.

Réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by