Subject: [SWIPL] Query: Building foreign libraries in prolog.

From: [email-masked]
Date: Tue, 8 Jan 2002 14:48:33 +0530

Hi All,

My platform is swi version 4.0.11 on Solaris 2.7.
We have built a prolog that contains some of the foreign code libraries included
in it.
Have adopted the following procedure for the same.

--------------------------- < Snip main.C  foreign code >
-------------------------
/* Include header files */
/* SWI-Prolog.h also included */

/* foreign function declarations */
/* for example */
extern "C"  foreign_t c_ts_connect(term_t, term_t);
...
...
PL_extension predicates[] =
{
  {"ts_connect",2,c_ts_connect,0},
...
...
  {NULL,0,NULL,0}
};

int main(int argc, char** argv)
{
  predicate_t pred;
  qid_t query;
...
...
  PL_register_extensions(predicates);
  if (!PL_initialise(argc,argv)) {
    fprintf(stderr, "couldn't initialize SWI\n");
    PL_halt(1);
  }
...
...
  pred = PL_predicate("check",0,"user");
  PL_call_predicate(NULL,0,pred,NULL);
  PL_toplevel();
...
...
  PL_halt(1);
}
--------------------------- < End Main file for C /c foreign code > -------------------------

Following are the compilation steps:
=============================
/usr/local/bin/g++ -c    -I/user/user2/SWI_XPCE/SWI-4.0.11/lib/pl-4.0.11/include
    -o main.o    main.C

/usr/local/bin/g++    -o  mypl    main.o   xml.o   dprintf.o   Portray_cl_lib.o
   glue.o \
   -L/user/user1/SWI_XPCE/SWI-4.0.11/lib/pl-4.0.11/runtime/sparc-solaris2.7 \
   -L/user/user2/tss1.8.10G/lib \
   -lpl -ltss -lnsl -lsocket -lpthread -lrt -ldl -lreadline -lcurses -lm
-------------------------------------------------------------------------------------------------------------

So, if I run "mypl" it gives me the prolog prompt with which I can execute the
API's
in the foreign code libraries.

My question is:
=============
I also need the functionality of xpce along with the other functionalities of my
 libraries
and the swi.
Is there any way I can make the xpce also available in the same executable,
"mypl".
The requirement also says that xpce should be statically linked so that I can
run the
same exe on the platform where swi / xpce is not installed.

I have an xpce version built with the static linking option i.e. swi + xpce. Can
 this built
be of some use in achieving the same.

Thanks in advance
Amir

Hughes Software Systems