编译C++使用SWI-Prolog接口的程序

Compiling C++ program that uses SWI-Prolog Interface

本文关键字:程序 接口 SWI-Prolog C++ 使用 编译      更新时间:2023-10-16

我正在编译这里找到的程序,在运行时出现错误:

这是我编译它的方法:

$ 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]

然后当我尝试运行编译的程序时:

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

我是否需要向我的.cpp文件添加一些内容以告诉它libswipl.so.6.0.2文件的位置?

您看到的问题与正在运行的a.out无法找到您的动态库有关。有几种依赖于系统的方法来处理此问题。例如,在 Linux 上,您可以将LD_LIBRARY_PATH设置为包含libswipl.so.6.0.2所在的目录。


尽管编译警告与运行时错误无关,但修复它们仍然是一个好主意:
static const char * av[] = {"calc.pl", NULL};
....
const char * expression = "pi/2";