[英]Can't find library boost.asio
I've been trying to run the following code taken from the boost site. 我一直在尝试运行以下来自Boost网站的代码。 It compiles, but when I try and run it, I get the following error: ./a: error while loading shared libraries: libboost_system.so.1.57.0: cannot open shared object file: No such file or directory
它可以编译,但是当我尝试运行它时,出现以下错误:./a:加载共享库时出错:libboost_system.so.1.57.0:无法打开共享库文件:没有这样的文件或目录
I've looked at all the similar answers on here, I've tried compiling with all, and each of the following: 我在这里查看了所有类似的答案,并尝试使用所有方法进行编译,以及以下各项:
g++ boost_server.cpp -oa -I /usr/local/include -L /usr/local/lib/ -lboost_system -lboost_filesystem g ++ boost_server.cpp -oa -I / usr / local / include -L / usr / local / lib / -lboost_system -lboost_filesystem
The headers and libraries are located in usr/local/include and /usr/local/lib respectively on my machine, which is running CentOS 标头和库分别位于运行CentOS的计算机上的usr / local / include和/ usr / local / lib中
It's the first time I've used it and I don't know what I"m doing wrong 这是我第一次使用它,我不知道自己做错了什么
#include <ctime>
#include <iostream>
#include <string>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
std::string make_daytime_string()
{
using namespace std; // For time_t, time and ctime;
time_t now = time(0);
return ctime(&now);
}
int main(){
try
{
boost::asio::io_service io_service;
tcp::endpoint endpoint(tcp::v4(), 13);
tcp::acceptor acceptor(io_service, endpoint);
for (;;)
{
tcp::iostream stream;
boost::system::error_code ec;
acceptor.accept(*stream.rdbuf(), ec);
if (!ec)
{
stream << make_daytime_string();
}
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
} }
return 0; 返回0; } ~
}〜
Tell the dynamic linker where your libraries are 告诉动态链接器您的库在哪里
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/" ./a
Either that, or use linker options to "bake in" the hint-paths (not recommended for deployments) 或者,或者使用链接器选项“引入”提示路径(不建议用于部署)
See also 也可以看看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.