0

I am compiling the program found here, and at runtime I get an error:

Here is what I do to compile it:

$ g++ -I/home/jpthomps/Desktop/pl-6.0.2/src main.cpp -L/usr/local/lib/swipl-6.0.2/lib/x86_64-linux -lswipl
main.cpp: In function ‘int main()’:
main.cpp:8:39: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
main.cpp:20:22: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

Then when I try to run the compiled program:

$ ./a.out
./a.out: error while loading shared libraries: libswipl.so.6.0.2: cannot open shared object file: No such file or directory

Do I need to add something to my .cpp file to tell it where the libswipl.so.6.0.2 file is located?

John Thompson
  • 1,674
  • 1
  • 20
  • 35

1 Answers1

1

The problem that you see is related to the inability of the running a.out to find your dynamic library. There are several system-dependent ways to deal with the issue. For example, on Linux you can set LD_LIBRARY_PATH to include the directory where libswipl.so.6.0.2 is located.


Although the compilation warnings are not related to the runtime error, it is still a good idea to fix them:
static const char * av[] = {"calc.pl", NULL};
....
const char * expression = "pi/2";
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523