Hi,
I am exploring the use of Wt library to have a Web interface to gretl
API (libgretl). This must be done in C++, and there are some
difficulties in using libgretl.
I have done the recommendation in this post
(
http://lists.wfu.edu/pipermail/gretl-users/2010-June/005026.html), to
add a compiler directive to libgretl.h. There was also the need to
change the name of a argument in a function declaration because it is
a reserved word in C++ (template).
These are the changes that need to be done in:
include/gretl/libgretl.h
+20,22
#ifdef __cplusplus
extern "C" {
#endif
+397,399
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
and in
include/gretl/gretl_path.h
changed at line 94 (inserted _ at *template)
FILE *gretl_mktemp (char *_template, const char *mode);
With this changes (that I hope that professor Allin commit them to
CVS), I successfully compiled and ran the example program (z.cpp):
#include <cstdio>
#include <iostream>
extern "C"
{
#include <gretl/libgretl.h>
}
using namespace std;
int main (int argc, char **argv)
{
cout << "Using libgretl from a C++ program:" << endl;
char *fname;
DATASET *dset;
PRN *prn;
int err;
if (argc >= 2) {
fname = argv[1];
} else {
exit(EXIT_FAILURE);
}
libgretl_init();
prn = gretl_print_new(GRETL_PRINT_STDOUT, NULL);
dset = datainfo_new();
err = gretl_read_native_data(fname, dset);
if (err) {
pprintf(prn, "Got error %d reading data from %s\n", err, fname);
errmsg(err, prn);
} else {
pprintf(prn, "Read data from %s OK\n", fname);
print_smpl(dset, 0, prn);
varlist(dset, prn);
}
destroy_dataset(dset);
gretl_print_destroy(prn);
libgretl_cleanup();
return 0;
}
Program was compiled with:
g++ -o z -Wall -I ./include/ -L ./lib/ z.cpp -lgretl-1.0 -lstdc++
Program takes a data file as argument, for example:
./z gretl/share/data/data10-1.gdt
Ouput is:
Using libgretl from a C++ program:
Read data from gretl/share/data/data10-1.gdt OK
Full data range: 1964:1 - 1991:2 (n = 110)
Listing 5 variables:
0) const 1) period 2) r 3) M 4) D
This info could be added to gretl API documentation, as an example to
use from C++.
Best Regards,
Hélio