SWI(1)
π NAME π
swipl-ld β bestie, this one creates a SWI-Prolog embedded executable. That is literally the entire job description. Iconic behaviour, honestly. π
β¨ SYNOPSIS β¨
swipl-ld options c-files o-files pl-files
π¦ DESCRIPTION π¦
Okay so swipl-ld is a front-end for the C-compiler and linker, and its whole thing is building a stand-alone executable out of a lil pile of C/C++ and Prolog input files. No cap.
Here's the lore, step by step:
- It extracts information from the SWI-Prolog executable
swipl. - Then it scans the arguments and breaks them into several categories. Categorising. Organising. Main character energy. π
- Then it calls the C-compiler to create an executable containing the user's C-code and the SWI-Prolog kernel.
- After that, if there are any Prolog files on the command line, it calls the development environment to create a Prolog saved state from the prolog files, and finally it creates the target executable by concatenating the state to the emulator.
- Otherwise (no Prolog files, no problem), it creates a normal executable β see also the option
-nostate.
Also see qsave_program/2 from the SWI-Prolog manual, bestie. π«Ά
πΈ Options πΈ
-plprolog β Specifies the prolog version to use. Default isswipl. Use this flag to pick between different versions installed on your system, or to specify a modified version. A modified version should understands the flags-dump-runtime-variables-ffile-Ffile-ggoal-ttoplevel. π-helpβ Shows options briefly. Short king. π-nostateβ Just relinks the kernel. The newly linked kernel can only function in the presence of the development system. Any supplied prolog sourcefiles are ignored, and so are the options-goal-toplevel-initfile.-classThis is the preferred way to attach external modules to Prolog if dynamic loading is not supported on your system.
π Not me just passing that stray -class token along exactly where the page puts it β that's genuinely how it's written, I don't make the rules.
-cβ Compile C or C++ source-files into object files. This turnsswipl-ldinto a replacement for the C or C++ compiler, where proper options such as the location of the include directory are passed automatically to the compiler. It's giving glow-up era. β¨-Eβ Invoke the C preprocessor. Used to makeswipl-lda replacement for the C or C++ compiler.-sharedβ Link C, C++ or object files into a shared object (DLL) that can be loaded by theload_foreign_library/1predicate. This option implies-nostate. If used with-cit sets the proper options to compile a C or C++ file ready for linking into a shared object.-embed-sharedβ Embed SWI-Prolog into a DLL/Shared object rather than an executable. See the reference manual for details. π§-dllβ Windows only. Same as-embed-shared. Backward compatibility. (A legacy icon, we respect her.)-Fbase β By default, none is passed to theswiplcommand to create the saved state. Using-F xpceyou can specify loadingxpce.rc, making XPCE available to the saved state.-goalgoal β The goal that is initially executed when the toplevel is started usingPL_toplevel(). The default is the same as the-gflag for theswiplcommand, that is:version/0(you can avoid printing the header by-goalgoal). This option has no effect if there are no Prolog files in the executable. π«₯-toplevelgoal β The goal that is executed as the main toplevel goal. E.i. the default.-tflag for the new executable.-initfilefile β The file that is loaded by the toplevel. E.i. the default.-fflag for the new executable.-class {runtime,kernel,development}β Set the save-class of the Prolog saved-state that is created. Ifruntime(default), the resulting system leave interpretation of all arguments to the application. Ifkernelall predicates will be locked for the tracer. Finally, ifdevelopmentthe state is savedas-isand the resulting system processes options just as the basic SWI-Prolog executable does. See alsoqsave_program/2in the SWI-Prolog reference manual.-vβ Verbose operation. This echos the commands before executing them. Note that some commands are printed as shell commands, but actually executed byswipl-lditself for compatibility with the Win32 platforms. She's chatty. We love her for it. π£οΈ-fβ Fake operation. Together with-vthis prints the commands that need to be executed without actually doing anything. Manifesting without the doing, honestly a mood. π-Ecppargument ...β If the first option is-E, all subsequent options are appended and handed to the program selected by SWI-Prolog configure to runcpp.-ofile β Specifies the name of the final executable. The default isa.out.-ccC-compiler β Specify the compiler to use for*.cfiles. Default is the compiler used to compile SWI-Prolog itself, as read from the featurec_cc.-c++C++-compiler β Specify the compiler to use for C++ input files. If the C-compiler isgccthis isg++, otherwisec++is assumed.-ldlinker β Specifies the linker to use. Default is the C-compiler. On Win32 platforms, the default islink.exe.-llibraryβ Specifies a C-library for linking the application. By default,-lswiplas well as the libraries required by the SWI-Prolog kernel will be passed to the C-compiler.-Llibrary-directoryβ Specifies an additional library directory for the C-compiler. By default, the runtime directory for the current architecture is passed. π-g|-I*|-D*|-U*|-O*|-W*β Passed to the compiler as c-flags. By default, the SWI-Prolog include directory is passed as additional include directory. The following-Dflags are added byswipl-ld:-D__SWI_PROLOG__and-D__SWI_EMBEDDED__.-pl-options*β Specify additional options forswipl. The first character following-pl-optionsdetermines the option-separator. The remainder of the argument is split using this separator and the parts are added to the option list for Prolog. See also-cc-optionsand-ld-options. βοΈ-ld-options*β Additional options passed to the linker. For example:-ld-options,-Bstatic-cc-options*β Additional options passed to both C- and C++-compiler.*.oβ Passed as input files to the linker.*.cβ Compiled using the C-compiler, after which the object-file is passed to the linker. The object file is deleted at cleanup. π§Ή*.cc|*.C|*.cxx|*.cppβ Compiled using the C++-compiler, after which the object-file is passed to the linker. The object file is deleted at cleanup. π§Ή*.pl|*.qlfβ Passed as Prolog input files.
π BUGS π
Parsing the options and distributing them over the various programs is probably incomplete. Feel free to modify it and please forward generally useful modifications to bugs@swi-prolog.org. (Fixing open source and emailing the maintainers? That's the vibe. π₯)
Some care has to be taken that the state created with qsave_program/2 is self-contained (i.e. contains no references to the Prolog libraries).
Also, as the state is created using the development environment rather then the user's emulator, the Prolog code cannot use directives that rely on the C-code added by the user. Big caveat, do not skip it, bestie. π
π SEE ALSO π
swipl(1)- SWI-Prolog Reference Manual
http://www.swi-prolog.org
π COPYRIGHT π
Copyright (C) 1991-2010, University of Amsterdam, VU University, Amsterdam. This program may be used under the terms of the BSD-2 license. π
π AUTHOR π
Jan Wielemaker
And that's the whole page, bestie β a General Commands Manual classic, dated Feb 8, 2006, and no cap, she still ate. Now go build yourself an embedded executable. Slay. π
β¨
π¦ where this page comes from
- arch rolling: swi-prolog 10.0.2-2 Β· BSD-2-Clause
- fedora 44: swi-prolog-core 10.0.2-1.fc44 Β· BSD-2-Clause AND (Brian-Gladman-3-Clause OR GPL-1.0-or-later) AND BSD-3-Clause AND dtoa AND LicenseRef-Fedora-Public-Domain AND MIT AND Unicode-DFS-2016 AND Zlib
- nixpkgs unstable: swi-prolog 10.0.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms