I understand that C code can be written in NMODL. What I'm wondering, though, is if that C code can contain wrappers to C++ objects/libraries. If so, is there a simple example of how to link?
Thanks,
Tom
C++ code via NMODL with C wrappers?
C++ in mod
You cannot include C++ in mod files.
However there are C++ packages in Neuron: vectors and lists that have wrappers compiled and therefore can be used. eg
extern void vector_resize();
extern int vector_instance_px();
One could use these examples to include an additional file in the initial build and provide wrappers for subsequent use in mod. I'm not sure how exactly how/where to add a new source file so that it gets picked up in the build sequence.
Bill
However there are C++ packages in Neuron: vectors and lists that have wrappers compiled and therefore can be used. eg
extern void vector_resize();
extern int vector_instance_px();
One could use these examples to include an additional file in the initial build and provide wrappers for subsequent use in mod. I'm not sure how exactly how/where to add a new source file so that it gets picked up in the build sequence.
Bill
Hi,
If you want to call your C++ functions from a C file, you will have to use the extern keyword when declaring or defining your C++ function:
Thereby, you specify that C's linkage conventions are being used.
Details on how to call C functions from the interpreter are given in this thread:
https://www.neuron.yale.edu/phpBB2/viewtopic.php?t=95
Contact me if you need sample code or more details. I hope I could help,
Christoph
You can add a C++ file to any directory (at least, it worked with the scopmath directory). Just name it *.cpp so that g++ and C++-specific compiler flags will be used instead of gcc. You will have to add it to the directory's Makefile.am as well and run automake and autoconf before building.I'm not sure how exactly how/where to add a new source file so that it gets picked up in the build sequence.
If you want to call your C++ functions from a C file, you will have to use the extern keyword when declaring or defining your C++ function:
Code: Select all
extern "C" void someCppFunc(/*...*/) {/*...*/}
Details on how to call C functions from the interpreter are given in this thread:
https://www.neuron.yale.edu/phpBB2/viewtopic.php?t=95
Contact me if you need sample code or more details. I hope I could help,
Christoph
Last edited by csh on Tue Apr 25, 2006 4:17 pm, edited 1 time in total.
It might not be too difficult to modify the nrnivmodl and nrniv_makefile scripts in nrn/bin (actually the *.in precursor files if you have autoconf/automake/libtool installed) to look at the suffixes of the files you pass to nrnivmodl (default is all the
mod files in the working directory). Then you could do anything you wanted with c++ and enclose what you wanted exposed to hoc in extern "C"{}. Then get all the c2hoc interface magic with a mod file that called them from FUNCTION or
PROCEDURE blocks. If you want an entirely new c++ class just like the ones
in the ivoc or nrniv source directories it should not be too difficult to call the
class2oc registration function from
a stub mod file.
The only problem with all this is that it will not work with the current mswin installer distribution since I supply only the minimal c development stuff and left out the c++ stuff.
mod files in the working directory). Then you could do anything you wanted with c++ and enclose what you wanted exposed to hoc in extern "C"{}. Then get all the c2hoc interface magic with a mod file that called them from FUNCTION or
PROCEDURE blocks. If you want an entirely new c++ class just like the ones
in the ivoc or nrniv source directories it should not be too difficult to call the
class2oc registration function from
a stub mod file.
The only problem with all this is that it will not work with the current mswin installer distribution since I supply only the minimal c development stuff and left out the c++ stuff.