How to access C function (random, srandom..) in NMODL files?

NMODL and the Channel Builder.
Post Reply
eacheon
Posts: 97
Joined: Wed Jan 18, 2006 2:20 pm

How to access C function (random, srandom..) in NMODL files?

Post by eacheon »

This is from obidos2004_NEURON_example_4 downloaded from http://www.neuron.yale.edu/ftp/neuron/c ... tutorials/
The .mod file compiles and when running main.hoc the mechanism does not get loaded.

In the .mod file the C function "random()" and "srandom()" are used with out any explicit context. When I was compiling mod files for Example 4, it compiles successfully but with some warning in gcc outputs:
gcc -mno-cygwin -I/cygdrive/h/nrn58/src/scopmath -I/cygdrive/h/nrn58/src/nrnoc -I/cygdrive/h/nrn58/src/oc -I/cygdrive/h/nrn58/lib -I/cygdrive/h/nrn58/mingw -c mod_func.c
nocmodl DGA_Destexhe
Translating DGA_Destexhe.mod into DGA_Destexhe.c
Notice: This mechanism cannot be used with CVODE
Warning: random undefined. (declared within VERBATIM?)
Warning: srandom undefined. (declared within VERBATIM?)

VECTORIZED
gcc -mno-cygwin -I/cygdrive/h/nrn58/src/scopmath -I/cygdrive/h/nrn58/src/nrnoc -I/cygdrive/h/nrn58/src/oc -I/cygdrive/h/nrn58/lib -I/cygdrive/h/nrn58/mingw -c DGA_Destexhe.c
rm DGA_Destexhe.c
ld -d -S -x -r -o nrnmech.dll mod_func.o DGA_Destexhe.o minimalExpSyn_Rudolph.o -L/cygdrive/h/nrn58/lib -lscpmt

nrnmech.dll was built successfully.
Then I double clicked main.hoc, seems some reference does not get defined. it shows:
loading membrane mechanisms from nrnmech.dll
Undefined symbol _random referenced from nrnmech.dll
Undefined symbol _srandom referenced from nrnmech.dll
Undefined symbol _exit referenced from nrnmech.dll

...
...
nrniv: DGA is not a template
in insertSynapticProperties.hoc near line 26
PRE[0] sExpSynGen = new DGA(0.5)
^
xopen("insertSynapticProperties.hoc" )
Is it due to a non complete build evironment under Win XP? What else do
I need to install?

Thanks a lot for your time and patience!
Last edited by eacheon on Wed Jan 25, 2006 10:21 pm, edited 1 time in total.
eacheon
Posts: 97
Joined: Wed Jan 18, 2006 2:20 pm

Post by eacheon »

I find this seems been asked before, but I can not see a direct solution found.
https://www.neuron.yale.edu/phpBB2/view ... =undefined
eacheon
Posts: 97
Joined: Wed Jan 18, 2006 2:20 pm

Re: How to access C function in NMODL files?

Post by eacheon »

eacheon wrote:
Is it due to a non complete build evironment under Win XP? What else do
I need to install?
No, I tried it on a Linux box but with NEURON 5.7, it gives out exactly the same results.

Have looked it a little. I guess what I want to ask is "How to access a C function in .mod file?". It seems people can do it simply and directly and without any error. But at my side, I can compile and get the "right" DLL file but the mechanism does not get recognized because it contains "undefined reference".
Raj
Posts: 220
Joined: Thu Jun 09, 2005 1:09 pm
Location: Groningen, The Netherlands
Contact:

Post by Raj »

I cannot answer the general question of how to access a C-function from mod, although the type of error messages hint at a linking problem.

To get the example you have working I think you can use the functions scop_random and setseed (defined in scoprand.c and made available for use in mod in scoplib.h ), of course you should be able to add your own functions this way aswell, but then you are developing a new version of NEURON. I cannot find exactly what the function of random and srandom used to be so I hope I'm guessing correctly.

There are two other possible directions for including c-functions:
- Specifying them in a verbatim block, with possible code duplication
- Analyzing the scripts for building the nrnmech.dll and making sure they link in the right c-functions.

I hope this at least partially answers your question.
eacheon
Posts: 97
Joined: Wed Jan 18, 2006 2:20 pm

Post by eacheon »

Raj wrote:I cannot answer the general question of how to access a C-function from mod, although the type of error messages hint at a linking problem.

To get the example you have working I think you can use the functions scop_random and setseed (defined in scoprand.c and made available for use in mod in scoplib.h ), of course you should be able to add your own functions this way aswell, but then you are developing a new version of NEURON. I cannot find exactly what the function of random and srandom used to be so I hope I'm guessing correctly.

There are two other possible directions for including c-functions:
- Specifying them in a verbatim block, with possible code duplication
- Analyzing the scripts for building the nrnmech.dll and making sure they link in the right c-functions.

I hope this at least partially answers your question.
I did have a look at the translated .c file and agree the problem could be solved. And you are right on the name of these 2 functions. Thanks for telling me that scoplib.h contains all C functions .mod files can use.

However when random is changed to "scop_random", srandom to "setseed". Now scop_random seems do the job while setseed seems not defined in libscopmt.a

Code: Select all

loading membrane mechanisms from nrnmech.dll
Undefined symbol _setseed referenced from nrnmech.dll
Undefined symbol _exit referenced from nrnmech.dll

this is strange.
Raj
Posts: 220
Joined: Thu Jun 09, 2005 1:09 pm
Location: Groningen, The Netherlands
Contact:

Nifty details

Post by Raj »

Try set_seed instead of setseed.

I found another header file likely to be involved in the specification of c-functions available to mod:
extdef.h

This one is included both in the nrn/src/modlunit and the nrn/src/nmodl source directories. This file specifies both setseed and set_seed. The file scoprand.c however is specifying set_seed() only and is also the source for scop_random() so that is probably the one you need.

In fact setseed is , in my copy of the source tree (2005-8-29 8:58:55 Main (66)), only declared at the level of a header file extdef.h and scoplib.h but never implemented.
hines
Site Admin
Posts: 1687
Joined: Wed May 18, 2005 3:32 pm

Post by hines »

Mod files under MSWIN are limited to calling only functions linked into the
nrnmech.dll file itself or the nrniv.exe functions listed in the file src/mswin/windll/(nrnmech.h nrnmath.h ocmatdll.h). On mac or linux there is no such restriction (every global name in the shared object is available to the executable and vice versa) so I am not quite sure what is meant by the statement
No, I tried it on a Linux box but with NEURON 5.7, it gives out exactly the same results.
So, apart from compiling NEURON from the sources after adding to the nrnmech.h file (which in any case depends on srandom actually existing in the executable), I think the best solution in this case is to put the implementation of srandom into the mod file. Consider, for example,
http://senselab.med.yale.edu/senselab/m ... 7/rand.mod
or else examine
c:/nrn58/lib/mknrndll.mak
and by analogy with how scpmt was added to the nrnmech.dll link rule, add your own gcc compiled library.
Raj
Posts: 220
Joined: Thu Jun 09, 2005 1:09 pm
Location: Groningen, The Netherlands
Contact:

Post by Raj »

Dear Michael,

A few questions to see whether I understand the situation correctly.

The extdef.h and extdef2.h files are just there to specify which strings should be recognized by the mknrndll ?

And this explains why srandom and random give a warning at build time (not present in extdef*.h and not implemented) where setseed only causes a problem at runtime (present in extdef*.h but not implemented) and set_seed works without any problems (both present in extdef*.h and implemented) ?

Regards,
Raj
Post Reply