Unable to compile sample crowtest.cpp with crow

789 Views Asked by At

I'm trying to run a sample c++ program using crow but getting the error fatal error: asio.hpp: No such file or directory

Installed crow using the instructions in https://crowcpp.org/master/getting_started/setup/linux/#installing-from-source

Followed the instructions and created a crow_all.h file.

Copied and created a sample crowtest.cpp program from the crow website

#include "crow_all.h"

int main()
{
    crow::SimpleApp app;

    CROW_ROUTE(app, "/")([](){
        return "Hello world";
    });

    app.port(18080).run();
}

Compiled the code g++ crowtest.cpp -o crowtest.o

But getting the following error

In file included from crowtest.cpp:1:
crow_all.h:931:10: fatal error: asio.hpp: No such file or directory
  931 | #include <asio.hpp>
      |          ^~~~~~~~~~
compilation terminated.

Note: Also installed boost using apt install libboost-dev

I'm new to c++ and crow, can anyone please help.

2

There are 2 best solutions below

0
sehe On

The include isn't the Boost Asio, but the standalone asio: https://think-async.com/Asio/AsioStandalone.html

They're practically the same, so you can probably also get it working with

#include <boost/asio.hpp>
namespace asio = boost::asio;

But if you don't feel confident that you know how to fix any issues, just download the expected version.

0
João Lemes On

The simple way to solve your problem is to just install this:

apt-get install libasio-dev