On Ubuntu 19.10: /usr/bin/ld: cannot find -llibswipl collect2: error: ld returned 1 exit status


My apology for posting again about gcc usage.

I now moved to ubuntu 19.10 w/ gcc.

Created a file mylib.cpp that has following contents:

#include <SWI-cpp.h>
#include <iostream>
#include <ostream>

PREDICATE(hello, 1)
{ std::cout << "Hello " << (char *)A1 << std::endl;

  return TRUE;

I then ran the following on a default swi installation:

gcc -shared -o mylib 
   -l libswipl 

but got the following error:

/usr/bin/ld: cannot find -llibswipl
collect2: error: ld returned 1 exit status

looks like i am still missing a last piece …

Btw, running

swipl-ld -o mylib mylib.cpp

Oddly returns the following despite the -o switch:

usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
/usr/bin/c++ returned code 256
*** swipl-ld exit status 1

any thoughts are much appreciated,


Must be -lswipl

Lacks -shared. The default is to create an embedded SWI-Prolog system.


It finally worked. I was able to load the library, after adding a path to the shared file via: 7 ?- assertz(file_search_path(foreign,’/home/dan/trial’)).

re: cout

Looks like i am immediately stumbling over the next issues.

I noticed that within Eclipse PDT, the string sent via cout doesn’t show up.

Is this a known issue?

thank you,


Yes. Various embeddings do not show cout. Typically you shouldn’t write output from library extensions. For debugging include <SWI-Stream.h> and use Sdprintf(), providing the usual printf() conventions (and some additional ones). This header provides interaction with the SWI-Prolog streams. There is no C++ binding :frowning:

1 Like

Care to make a wiki?

While I don’t need one at present for this, I am sure others would agree it would be nice to have one when needed. :grinning:

1 Like

Several probably, but one on how to compile and link an extension on various platforms can be quite useful. Notably on Windows it is a bit of a challenge :frowning:

1 Like