4

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.

  • You need to tell your compiler where to find boost headers. Do this with the `-I` flag. – erip Jan 04 '23 at 20:39
  • C++ compilers look in a set of compiler specific locations to find header files. If the header you want to be found isn't in one of those locations then you need to tell the compiler where to look. Since you are using `g++` you need to add `-I` to your command line where `` is the place on your system that the compiler can find `asio.hpp` – john Jan 04 '23 at 20:39

2 Answers2

3

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

apt-get install libasio-dev
1

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.

sehe
  • 374,641
  • 47
  • 450
  • 633