简体   繁体   中英

Can't find library boost.asio

I've been trying to run the following code taken from the boost site. 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

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

The headers and libraries are located in usr/local/include and /usr/local/lib respectively on my machine, which is running CentOS

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; } ~

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM