r2 - 06 Nov 2002 - 10:14:01 - JanWielemakerYou are here: TWiki >  FAQ Web  > LibAndInclude

Where are SWI-Prolog.h and the library files?

SWI-Prolog.h is in the include directory of the distribution. The distribution is normally installed in C:\Program Files\pl on Windows and /usr/local/lib/pl-<version> on Unix.

On Unix, by default only the library for static linking libpl.a is installed in the =lib/<arch> subdirectory of the installation. On Windows, the import library libpl.lib is in the lib subfolder and libpl.dll is in the bin subfolder.

To compile C/C++ objects you need to add the include subfolder to the include directories of your compiler or you can use the plld utility. The command below creates file.obj (Windows) or file.o (Unix), passing the proper include directory to the C-compiler. This requires the SWI-Prolog programs to be available from the PATH environment variable.

plld -c file.c

To link C/C++ objects to a shared-object (DLL) you need to links agains libpl.lib on Windows. On ELF based Unix platforms (most today), you do not need an import library. Often, it is much easier to let plld do the job as in the command below, which creates file.dll or file.so depending on the platform.

plld -shared -o file file.o

To embed SWI-Prolog in a C/C++ main program you need to link against the libpl library on all platforms. Using libpl.a on Unix you also need to link against whatever libraries were needed on the system to link Prolog. Again, plld implifies the process. The first command embeds the Prolog kernel in a C main program and the second attaches a Prolog state to the result, creating a stand-alone executable.

plld -o myexe -nostate file.o ... plld -o myexe file.o ... file.pl ...

Learning from plld.

If you don't want to use plld, you can learn from it by adding the -v option to the commandline, which causes the program to print the commands it runs to do its job.

See also EmbedWinSetup

-- JanWielemaker - 01 Oct 2002

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback