Files
You need to prepare header files [xxx.h] which includes
interface of the encapsulated C/C++ library. You also need
either source files [xxx.C] [xxx.c], object files [xxx.o],
library files [xxx].a or combination of those.
Procedure
1) Create a Makefile
First of all, you need to create a Makefile by using
makecint. Makecint will automate a process of generating
Makefile. In following example, makecint will create a
Makefile which compiles "mycint" executable. The "mycint"
embeds xxx.C and yyy.o as precompiled library.
$ makecint -mk Makefile -o mycint -H xxx.h yyy.h -C++ xxx.C yyy.o
Command line options will be explained later in this document.
2) Modify Makefile (if needed)
Please check the created Makefile and modify it if needed.
If your library is simple, modification may not be needed.
However, when linking non-trivial libraries, you may need
to carefully examine and modify Makefile by hand.
3) Do make
Do make. "mycint" will be compiled and linked. "mycint" is
a customized C/C++ interpreter which pre-includes
interface to xxx.h and yyy.h.
$ make
Inside the make, Cint is invoked for making dictionary
source code G__cpp_[XXX].C and/or G__c_[XXX].c. These source
files include interface methods for enabling seamless
access between the interpreter and a compiled code.
Examples
/usr/share/doc/cint/demo/makecint directory contains examples.
Refer to /usr/share/doc/cint/demo/makecint/README.txt for
details.
Class members
Public member of classes and structs can be accessed from the
interpreter. You can not access private and protected members from the
interpreter. Size of class/struct objects and data-member/base-class
offsets match to the compiled code. (If you use a special technique,
you can access protected member from the interpreter. SEE '#pragma
link C++ class+protected')
Template
Instantiated template class and template function can be
accessed from the interpreter. Template itself can not
be precompiled.
typedef
Typedef information is precompiled and can be used from
the interpreter.
Inheritance, Class object as member
Inheritance and class object members are handled properly when they
are precompiled. Precompiled class can be a super-class of an
interpreted class. Also, object of precompiled class can be a member
of an interpreted class. Virtual function defined in precompiled
class is only virtual within the precompiled object because compiler
and interpreter has different virtual function resolution
mechanism. There will be a possible enhancement in the future.
Default constructor, copy constructor , destructor
If one of default constructor, copy constructor or destructor is
declared private (or protected), the class can not be accessed from
the interpreter.
$ makecint -mk Makefile -o mycint -H prog.h -C++ prog.C
$ make
Will make customized cint "mycint" including prog.C user specific
library.
$ makecint -mk Makefile -dl func.dl -H func1.h func2.h -C++ func1.C func2.C
$ make
This will generate a DLL 'func.dl' which includes Position Independent
Code of func1.C, func2.C. -dl option compiles user specific Suffix of
the dynamic link library can be either '.dl', '.sl', or '.DLL'. You
can link func.dl by passing it to cint. Multiple DLL can be linked at
a time if there is no cyclic symbol dependency.
$ cint func.dl othersource.c
$ cint func1.dl func2.dl othersource.c
You can link the DLL by '#include' or '#pragma include' statement in
the source code. '#include' and '#pragma include' behaves exactly the
same except that when you try to compile the source code by a
compiler '#include' will cause an error.
// Interpreted source file
#include "func1.dl"
#pragma include "func1.dl"
main() {
.
}
Operation of the dynamic link library function/global/stub are
identical to that of archived version. Option '-o' and '-m' can not
be used with '-dl'. Installation and all makecint activity must be
done under same OS and compiler environment.
$ makecint -mk make.prog1 -o prog1 -H prog1.h -C++ prog1.C
$ make -f make.prog1
$ prog1
$ makecint -mk Makeit -p -o mycint -H prog.h -C++ prog.C
$ make -f Makeit
This option is being obsoleted. Use +P,-P instead.
/* Example host program host.c
* $ makecint -mk Makefile -o host -m -I$CINTSYSDIR -h host.h -C host.c
* $ make
*/
#include <G__ci.h>
#include "host.h" /* host.h can be an empty file */
main() {
int state;
char command[100], macrofile[100], *p;
state=G__init_cint("cint");
while(0==state) {
strcpy(macrofile,G__input("Input macro file >"));
if(strcmp(macrofile,"exit")==0) break;
if(0==G__loadfile(macrofile)) {
strcpy(command,macrofile);
p = strchr(command,'.');
if(p) {
strcpy(p,"()");
G__calc(command);
}
G__unloadfile(macrofile);
}
}
G__scratch_all();
}
int G__init_cint(char* command)This function will initialize Cint. main() is automatically executed if it exists and returns 1. If main() is not found it returns 0. It returns -1 if initialization fails.
int state;
state=G__init_cint("cint source.c");
// 0==state : initialized but no main()
// 1==state : initialized and main() called
// -1==state: initialization failed
After the initialization you can use following functions.
G__value G__calc(char* expression)This function evaluates C/C++ expression as string. Returned value is in the form of generic object G__value. G__value can be translated to long or double value by 'int G__int(G__value val)' or 'double G__double(G__value val)' functions. For example,
// double f(int a) and void g(void) in source.c
double d;
G__init_cint("cint source.c");
G__calc("g()");
d=G__double(G__calc("f(1234)"));
G__scratch_all();
long G__int(G__value buf)This function converts G__value object to a long int value.
double G__double(G__value buf)This function converts G__value object to a double precision float value.
int G__loadfile(char* filename)This function loads C/C++ source code or Dynamic Link Library(DLL). If suffix of the filename is .dl, .sl, .so, .dll or .DLL, the file is linked as DLL. Otherwise, C/C++ source file. It returns 0 if the file is successfully loaded, 1 if the file is already loaded and -1 if the file can not be loaded. In case of fatal error, it returns -2.
G__init_cint("cint");
G__loadfile("src1.C");
G__loadfile("myLib.dl");
G__loadfile("src2.c");
G__calc("f()");
int G__unloadfile(char* filename)This function unloads C/C++ source code or Dynamic Link Library(DLL). In order to keep consistency, all the files loaded after the specified file will be unloaded. It returns 0 if files are successfully unloaded, -1 if not. It first checks if any of the function defined in the unloading files are busy.
G__init_cint("cint src0.c");
G__loadfile("src1.C");
G__loadfile("myLib.dl");
G__loadfile("src2.c");
G__loadfile("src3.C");
....
G__unloadfile("src2.c"); // unload src2.c and src3.C
....
G__loadfile("src4.C");
....
G__unloadfile("src4.C"); // unload src4.C
....
G__unloadfile("src0.c"); // unload all files
int G__pause(void)This function starts debugger interface. It returns 0 except 'i'(ignore) or 'q'(quit) command is used. You can start interactive interface as follows.
G__init_cint("cint source.c");
while(G__pause()==0); // pause until 'i' command
G__scratch_all();
char* G__input(char* prompt)This function is a command line input frontend function. Although this is not an essential function to the C/C++ interpreter, this is often convenient because readline history and command line editing capability is built-in using GNU readline library. This function returns a pointer to a static string buffer.
char *buf[100];
G__init_cint("cint");
strcpy(buf,G__input("Input your command >");
G__calc(buf);
void G__scratch_all(void)This function terminates interpreter. All the files are unloaded and environment is reset.
$ makecint -mk Makeit -DONLINE -o mycint -H source.h -C++ source.C
$ make -f Makeit
$ makecint -mk Makeit -I/users/include -I/include -H src.h -C++ src.C
$ make -f Makeit
$ makecint -mk Mkit -o mycint -H src1.h src2.h -C++ src1.C src2.C
$ make -f Mkit
SUTPI.h file must be compliant to cint syntax limi tations described
in /usr/share/doc/cint/limitati.txt. If SUTPI.h uses C++ language
constructs which is not supported by cint, that part must be excluded
by "#ifndef __MAKECINT__" or "#ifndef __CINT__". The macro __CINT__ is
defined both for cint and makecint and __MAKECINT__ is defined only
for makecint.
class A {
// supported feature
#ifndef __MAKECINT__
// unsupported feature
#endif
};
$ makecint -mk Makeit -A -o mycint -h csrc1.h csrc2.h -C csrc1.c csrc2.c
$ make -f Makeit
SUTPI.h file must be compliant to cint syntax limitations described
/usr/share/doc/cint/limitati.txt. If SUTPI.h uses C++ language
constructs which is not supported by cint, that part must be excluded
by "#ifndef __MAKECINT__" or "#ifndef __CINT__". The macro __CINT__ is
defined both for cint and makecint and __MAKECINT__ is defined only
for makecint.
$ makecint -mk Makeit -o mycint -H A.h B.h +P C.h D.h -P E.h F.h -C++ all.C
$ make -f Makeit
$ makecint -mk Makeit -o mycint -H A.h B.h +V C.h D.h -V E.h F.h -C++ all.C
$ make -f Makeit
Class title has to be described in class/struct defi- nition in header
file as follows. Basically, '//' style comment right after each
member declaration will be loaded as class member comment.
class ABC {
int a; // title of the member variable
double b; // title of the member variable
int c(); // title of the member function
ClassDef(ABC) // title of the class
} ;
#### Example is in /usr/share/doc/cint/demo/makecint/Stub directory $ makecint -mk Makefile -o mycint -H Src.h -i++ Stub.h -C++ Src.C $ make -f Makefile $ mycint Stub.CSTUB.h file must be compliant to cint syntax limitations described in /usr/share/doc/cint/limitatitxt. Only non-static global functions can be specified in STUB.h file. Behavior of class, struct, union, enum and non-static global variable defined in STUB.h is undefined.
$ makecint -mk Makefile -o mycint -h Src.h -i Stub.h -C Src.c $ make -f Makefile $ mycint Stub.cSTUB.h file must be compliant to cint syntax limitations described in man page file /usr/share/doc/cint/limitati.txt. Only non-static global functions can be specified in STUB.h file. Behavior of struct, union, enum and non-static global variable defined in STUB.h is undefined.
$ makecint -mk Makeit -u undef.h -H src.h -C++ src.C
$ make -mk Makeit
This option is not perfect. If you find problem, you need to fix it
manually.
$ makecint -mk makefile -dl src.dll -I/x/inc -U/x/inc -H src.h
$ make -f makefile
$ cint src.dll
Suppose you have /x/inc/mylib.h and it is included from src.h, things
defined in /x/inc/mylib.h can not be accessed from the interpreter.
// src.h
#include <string> // this will trigger implicit loading
class myclass { .. };
$ makecint -mk makefile -dl src.dll -Z1 -H src.h
$ make -f makefile
$ cint src.dll
cint> .file
0: myheader.dll // explicitly loaded
1: string // loaded implicitly by shared library
2: string.dll // "
3: bool.h // "
#define G__IS_OPERATOR_NEW 0x01Global operator new is found in user header file. Cint automatically stops generating operator new function in the dictionary.
#define G__IS_OPERATOR_DELETE 0x02Global operator delete is found in user header file. Cint automatically stops generating operator delete function in the dictionary.
#define G__MASK_OPERATOR_NEW 0x04Cint does not generate operator new function in the dictionary because it is explicitly masked by -M0x4 command line option.
#define G__MASK_OPERATOR_DELETE 0x08Cint does not generate operator new function in the dictionary because it is explicitly masked by -M0x8 command line option.
#define G__NOT_USING_2ARG_NEW 0x10Cint uses operator new function with 1 argument in dictionary source code.
#define G__DUMMYARG_NEWDELETE 0x100If this flag is set, a new operator new/delete scheme is turned on. With this scheme, cint dictionary generates following functions.
void* operator new(size_t size,[DLLID]_tag* p);
void operator delete(void *p,[DLLID]_tag* x);
static void G__operator_delete(void *p);
#define G__DUMMYARG_NEWDELETE_STATIC 0x200This flag makes operator new a static function. So, following functions will be generated.
static void* operator new(size_t size,[DLLID]_tag* p);
static void operator delete(void *p,[DLLID]_tag* x);
static void G__operator_delete(void *p);
Default value is -M0x100 for pure CINT and -M0x1c for ROOTCINT.
$ makecint -mk Makeit -H src.h -C++ src.C -cint -M0x1c
$ make -mk Makeit
If you have one argument operator new in your source code, your
operator new should look like below.
#define G__PVOID (-1)
extern "C" long G__getgvp();
void* operator new(size_t size) {
if(G__PVOID!=G__getgvp()) return((void*)G__getgvp());
// Yourown things...
}
If you have two argument operator new in your source code, your
operator new should look like below.
#define G__PVOID (-1)
extern "C" long G__getgvp();
void* operator new(size_t size,void* p) {
if((long)p==G__getgvp() && G__PVOID!=G__getgvp()) return(p);
// Yourown things...
}
If you have operator delete in your source code, your operator
delete should look like below.
#define G__PVOID (-1)
extern "C" long G__getgvp();
void operator delete(void *p) {
if((long)p==G__getgvp() && G__PVOID!=G__getgvp()) return;
// Yourown things...
}
// src.h
#include <string> // this will trigger implicit loading
class myclass { .. };
$ makecint -mk makefile -dl src.dll -H src.h -cint -Z1
$ make -f makefile
$ cint src.dll
cint> .file
0: myheader.dll // explicitly loaded
1: string // loaded implicitly by shared library
2: string.dll // "
3: bool.h // "