1

I am writing a multiplatform program in c++ that should run on AMD and Raspberry Pi 4.

On AMD I installed cpp-httplib-dev like this: sudo apt-get install libcpp-httplib-dev

and then the code like below works just fine.

#include <httplib.h>
...
httplib::Server svr;
svr.Get("/hi", [](const httplib::Request &, httplib::Response &res) 
 { res.set_content("Hello", "text/plain");});
std::thread _thread( [&](){svr.listen("0.0.0.0", 8080);} );

But I cannot install such a library on Raspberry Pi.

I was looking for something similar to apt search with no results for C++.

Question: Is it possible to create a simple HTTP server on Raspberry Pi with just C++? If yes, how?

If not, what are possible solutions?

NOTE: My project is quite big and must be in C++. Eventually, I can have the server part written in another compilable language, but how then pass information between those programs?

(Then just need to pass simple strings between programs, like: "R1 Down", "R4 R5 R8 Up")

asked Jan 1, 2024 at 16:12
1
  • on my PI's apt show libcpp-httplib-dev suggests the package does exist - what version of Raspbbery Pi OS have you got installed? Commented Jan 2, 2024 at 1:16

1 Answer 1

1

I've never used httplib before, but a quick check on an x86-64 machine reveals an important point:

cpp-httplib-devel.x86_64 : A C++11 single-file header-only cross platform HTTP/HTTPS library
 ^^^^^^^^^^^^^^^^^^^^^^^

If you are new enough to C++ that you don't know what a "header only" library is, you may want to look that up, but in short this means the library is a single .h/.hpp file which only requires you #include the header in order to use it -- there is no separate pre-existing compiled object that needs to be linked in. Hence, there is not actually a set of binary packages, each targeting a different architecture. There is only the header file, which is textual C++ code.

Why it then isn't available in Raspbian I don't know, but since it is apparently also cross-platform, all you need to do to use it on the Pi is copy the one file over and you can attempt to compile your project with that without doing anything else.

Is it possible to create a simple HTTP server on Raspberry Pi with just C++?

Even without any http library, yes, but you would have to write the whole thing yourself, which for a complete general purpose server would be quite a bit of work.

answered Jan 1, 2024 at 16:47
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.