将 c++ 程序与 lpsolve 链接时出现问题 api

Problem when linking c++ program with lpsolve api

我在链接我的 C++ 程序时遇到了一些问题,这是我所做的: g++ tp.cpp -llpsolve55 -lcolamd -ldl -o MyExe 和命令行 return 我这个:

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

但我已经安装了 lpsolve,它在 Synapatic 中显示为已安装,我什至通过终端安装了它

如果 /usr/lib/lp_solve 不在库的正常搜索路径中,您可以在链接时将该路径添加到可执行文件中。另请注意,库通常应排在最后:

g++ -o MyExe tp.cpp -L /usr/lib/lp_solve  -Wl,-rpath,/usr/lib/lp_solve -llpsolve55 -lcolamd

-L 参数将目录添加到目录列表中,以便在进行链接时在其中查找库。

-Wl 告诉编译器将后面的内容传递给链接器。

链接器 -rpath,<path> 参数告诉它将 <path> 添加到 MyExe 以便稍后 运行 程序时它可以找到库。