For example:
- You have header file for C routines:
#ifndef __CINT__
#ifdef __cplusplus
extern "C" {
#endif
#endif
enum ml_status { mlOK, mlFATAL };
extern int ml_init(int);
extern int ml_exit();
#ifndef __CINT__
#ifdef __cplusplus
}
#endif
#endif
- Make LinkDef file:
/*----- file mlLinkDef.h ------*/
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C function ml_init;
#pragma link C function ml_exit;
#pragma link C enum ml_status;
#endif
- generate dictionary:
$ rootcint -f mlDict.cxx -c ml.h mlLinkDef.h
- Compile C++ dictionary code:
$ g++ -fPIC -I$ROOTSYS/include -c mlDict.cxx
- Compile C source, ml.c:
$ gcc -fPIC -c ml.c
- Link into shared library, using the C++ compiler needed to add
correct init code for the global objects in the dictionary:
$ g++ -shared -o ml.so ml.o mlDict.o
- Now you have a shared library containing your C code plus the CINT
dictionary information. To use it do:
$ root
root [0] gSystem.Load("ml")
(int)0
root [1] ml_init(2)
this is ml_init ini=2
(int)0
root [2] ml_exit()
this is ml_exit
root [3] mlFATAL
(enum ml_status)1
root [4] .q
Cheers, Fons.
Masaharu Goto wrote:
>
> >
> >I would love to be able to load precompiled ANSI C functions without the need
> >to construct my own classes and recompile cint/root. May be this is already
> >possible?
>
> You can do this already. Unfortunately, rootcint does not support this
> capability, but makecint does. You need to install bare cint, then
>
> $ makecint -mk Makefile -dl cprog.dll -h cprog.h -C cprog.c
> $ make -f Makefile
>
> Then you will have cprog.dll which contains your ANSI C functions.
> You can load this dll just like other shared libraries. Please read
> doc/makecint.txt for detail.
>
> Masaharu Goto
-- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248 WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7677910