Page 1 of 1

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

Posted: Tue May 20, 2014 12:59 am
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

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

Posted: Tue May 20, 2014 9:04 pm
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

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

Posted: Wed May 21, 2014 3:38 am
by Zedong Bi
Thank you. In this way, a large amount of c++ libraries will be available to neuron