next up previous contents index
Next: A simple example Up: Foreign Language Interface Previous: Embedding SWI-Prolog in a   Contents   Index


Linking embedded applications using plld

The utility program plld (Win32: plld.exe) may be used to link a combination of C-files and Prolog files into a stand-alone executable. plld automates most of what is described in the previous sections.

In the normal usage, a copy is made of the default embedding template .../pl/include/stub.c. The main() routine is modified to suit your application. PL_initialise must be passed the program-name (argv[0]) (Win32: the executing program can be obtained using GetModuleFileName). The other elements of the command-line may be modified. Next, plld is typically invoked as:



plld will first split the options into various groups for both the C-compiler and the Prolog compiler. Next, it will add various default options to the C-compiler and call it to create an executable holding the user's C-code and the Prolog kernel. Then, it will call the SWI-Prolog compiler to create a saved state from the provided Prolog files and finally, it will attach this saved state to the created emulator to create the requested executable.

Below, it is described how the options are split and which additional options are passed.

-help Print brief synopsis. -plprolog Select the prolog to use. This prolog is used for two purposes: get the home-directory as well as the compiler/linker options and create a saved state of the Prolog code. -ldlinker Linker used to link the raw executable. Default is to use the C-compiler (Win32: link.exe). -ccC-compiler Compiler for c files found on the commandline. Default is the compiler used to build SWI-Prolog (see current_prolog_flag2) (Win32: cl.exe). -c++C++-compiler Compiler for C++ sources (extensions cpp, cxx, cc or C) files found on the commandline. Default is c++ or g++ if the C-compiler is gcc) (Win32: cl.exe). -nostate Just relink the kernel, do not add any Prolog code to the new kernel. This is used to create a new kernel holding additional foreign predicates on machines that do not support the shared-library (DLL) interface, or if building the state cannot be handled by the default procedure used by plld. In the latter case the state is created seperately and appended to the kernel using cat kernel state > out (Win32: copy /b kernel+state out) -pl-options,... Additional options passed to Prolog when creating the saved state. The first character immediately following pl-options is used as separator and translated to spaces when the argument is built. Example: -pl-options,-F,xpce passed -F xpce as additional flags to Prolog. -ld-options,... Passes options to the linker, similar to -pl-options. -cc-options,... Passes options to the C/C++ compiler, similar to -pl-options. -v Select verbose operation, showing the various programs and their options. -ooutfile Reserved to specify the final output file. -llibrary Specifies a library for the C-compiler. By default, -lpl (Win32: libpl.lib) and the libraries needed by the Prolog kernel are given. -Llibrary-directory Specifies a library directory for the C-compiler. By default the directory containing the Prolog C-library for the current architecture is passed. -g -Iinclude-directory -Ddefinition These options are passed to the C-compiler. By default, the include directory containing SWI-Prolog.h is passed. plld adds two additional -Ddef flags:
-D__SWI_PROLOG__ Indicates the code is to be connected to SWI-Prolog. -D__SWI_EMBEDDED__ Indicates the creation of an embedded program.
*.o *.c *.C *.cxx *.cpp Passed as input files to the C-compiler *.pl *.qlf Passed as input files to the Prolog compiler to create the saved-state. I.e. all other options. These are passed as linker options to the C-compiler.



Subsections
next up previous contents index
Next: A simple example Up: Foreign Language Interface Previous: Embedding SWI-Prolog in a   Contents   Index
Dr. Richard Botting 2001-12-12