Minimal build with STATIC_EXTENSIONS

Thank you.

For your kind consideration: I still have the issue with (e.g., Linux)

$ cmake -DSTATIC_EXTENSIONS=TRUE -DSWIPL_SHARED_LIB=OFF -DSWIPL_STATIC_LIB=ON ..
$ make
...
[ 27%] Linking CXX executable swipl
/usr/bin/ld: libswipl.a(pl-load.c.o):(.data+0x178): undefined reference to `install_test_cpp'

and don’t know how to get rid of it (other than by enumerating all packages with -DSWIPL_PACKAGE_LIST=…). There doesn’t seem to be a function install_test_cpp in the code (?)

I just pushed a fix for that (do not build the foreign language tests if STATIC_EXTENSIONS is given). Also pushed some changes that prevent installing the static libraries. Probably some more cleanup of what is installed is possible.

With that, this is enough to end up with a 5Mb executable that contains all standard extensions except those that require dynamic linking (jpl and sweep).

cmake -DSTATIC_EXTENSIONS=ON -G Ninja ..

Passes all tests, seems to work well, including graphics (on Linux).

Note that you do not need -DSWIPL_SHARED_LIB=OFF as this is implied by -DSTATIC_EXTENSIONS=ON and you also do not need -DSWIPL_STATIC_LIB=ON, which is there to force building and the static libswipl in addition to the dynamic one.

1 Like

One more question :slight_smile: This time, it is macOS. The swipl.pc seems to be missing (?). It’s there in the dynamic build, but not in the static build.

dynamic:

[100%] Built target library_index_library_http_always
Install the project...
-- Install configuration: "Release"
echo `ls ../inst/swipl`
bin lib share
echo `ls ../inst/swipl/share`
man pkgconfig
echo `ls ../inst/swipl/share/pkgconfig`
swipl.pc

static:

[100%] Built target memfile
[100%] Built target clib
[100%] Built target test_certificates
Install the project...
-- Install configuration: "Release"
echo `ls ../inst/swipl`
bin lib share
echo `ls ../inst/swipl/share`
man <<<--- no pkgconfig folder
echo `ls ../inst/swipl/share/pkgconfig`
ls: ../inst/swipl/share/pkgconfig: No such file or directory

Its installation is explicitly skipped in src/CMakeLists.txt. As no library is installed there is no point having this.

All right. Suppose I want the static libswipl.a with the extensions to be embedded, pkgconfig may be helpful.

I see however, that I may be able to use libswipl.a from src instead (the non installed version).

A post was split to a new topic: C++ interface inline or not?

libswipl.a only contains the core and an array with the entry points of the packages. The only thing you can do with it is to link it together with exactly the list of packages it was configured with to an executable.

As is, it can do only one thing: create a single executable with a selected set of packages distributed with the system. There are surely other scenarios that are useful, but that is another discussion.

I guess you know my specific use case, namely, a standalone dll/so/dynlib (instead of an executable) with swipl and the extensions in single one file. Why? Nothing special, the shared lib works well, it’s basically because the R/CRAN people prefer one single dll in their package system.

It’s not urgent, so I’ll tinker around with it when I have time and, if I am successful, I’ll submit a PR.

I forgot about that. It could be what the R/CRAN people want. It is not going to give you a flexible system though.