Hi there, I am interfacing a C++ library to GNU Prolog and I have encountered a couple of problems. The first is due to the fact that gprolog.h uses a the C++ reserved identifier `template'. It does that at line 639: char *M_Mktemp(char *template); Notice that this problem is not solved by replacing #include <gprolog.h> with extern "C" { #include <gprolog.h> } One may indeed resort to the ugly extern "C" { #define template templ #include <gprolog.h> #undef template } but I believe avoiding using any C++ reserved identifier is a much better solution. While we are at it, we may wish to make the C++ user's life a bit simpler by enclosing gprolog.h withing #ifdef __cplusplus extern "C" { #endif and #ifdef __cplusplus } #endif The header gprolog.h has the multiple inclusion guard #ifndef _GP_CONFIG_H #define _GP_CONFIG_H ... #endif but the guard's #endif is, in the case of gprolog.h NOT at the end of the file (why?). As a result, if gprolog.h is included twice you get tons of redefinition errors. Can this be fixed? The last problem concerns the installation of gprolog.h: it is not put in any path where C/C++ compilers would look for it. While it is OK to have it in $prefix/gprolog-1.2.8/include/gprolog.h it would be handy if the installation procedure could set up a symbolic link to it in, say, $prefix/include/gprolog.h (unless the user explicitely requests something else, of course). I enclose a patch to gprolog.h for the template, C++ and inclusion guard problems. All the best, Roberto -- Roberto Bagnara Computer Science Group Department of Mathematics, University of Parma, Italy http://www.cs.unipr.it/~bagnara/ mailto:bagnara@cs.unipr.it *** gprolog.h.~1~ Fri Oct 26 11:14:03 2001 --- gprolog.h Fri Oct 26 11:57:09 2001 *************** *** 25,30 **** --- 25,35 ---- /* $Id: headers.h,v 1.3 2001/01/23 11:38:20 diaz Exp $ */ #ifndef _GP_CONFIG_H #define _GP_CONFIG_H + + #ifdef __cplusplus + extern "C" { + #endif + #define HAVE_TERMIOS_H 1 #define HAVE_MALLOC_H 1 #define HAVE_MMAP 1 *************** *** 143,149 **** #define FC #endif #endif /* !_ARCH_DEP_H */ - #endif /* !_GP_CONFIG_H */ #define MAX_OBJECT 1024 #define START_PRED_TBL_SIZE 4096 #define START_OPER_TBL_SIZE 1024 --- 148,153 ---- *************** *** 636,642 **** int M_Spawn_Redirect(char *arg[], int detach, FILE **f_in, FILE **f_out, FILE **f_err); int M_Get_Status(int pid); ! char *M_Mktemp(char *template); char *M_Tempnam(char *dir, char *pfx); #define DBGPRINTF printf void Init_Machine(void); --- 640,646 ---- int M_Spawn_Redirect(char *arg[], int detach, FILE **f_in, FILE **f_out, FILE **f_err); int M_Get_Status(int pid); ! char *M_Mktemp(char *templ); char *M_Tempnam(char *dir, char *pfx); #define DBGPRINTF printf void Init_Machine(void); *************** *** 2324,2326 **** --- 2328,2336 ---- void Full_Max_Cst_Var(Range *z, int a, Range *x); void Full_Min_Cst_Var(Range *z, int a, Range *x); #endif /* NO_USE_FD_SOLVER */ + + #ifdef __cplusplus + } + #endif + + #endif /* !_GP_CONFIG_H */
participants (1)
-
Roberto Bagnara