Whether it is possible to insert c++ in .mod file

NMODL and the Channel Builder.
Post Reply
Zedong Bi

Whether it is possible to insert c++ in .mod file

Post by Zedong Bi »

Hi all,

I wonder whether we could add c++ command in .mod file. nrnivmodl will first convert .mod file into .c file, and then compile the .c file using gcc. However, I wonder how to compile the .c file using g++, in which case we can add c++ code in the .mod file between VERBATIM and ENDVERBATIM.

Zedong
hines
Site Admin
Posts: 1692
Joined: Wed May 18, 2005 3:32 pm

Re: Whether it is possible to insert c++ in .mod file

Post by hines »

You cannot put c++ code in mod file VERBATIM blocks. However you can build a c++ library and when you run nrnivmodl give it the option
nrnivmodl -loadflags='libmylibrary.so'
or perhaps ...='-L. -lmylibrary'
or perhaps ...='libmylibary.a'
depending on how you linked your library. Anyway, the functions and variables available from your library should have c access via the idiom
extern "C" {
// C prototypes of what you want to have available to the mod file
}

then in a mod file you can use
VERBATIM
// use any of the extern "C" prototypes defined in your libarry
ENDVERBATIM
Zedong Bi

Re: Whether it is possible to insert c++ in .mod file

Post by Zedong Bi »

Thank you. In this way, a large amount of c++ libraries will be available to neuron
Post Reply