-
Notifications
You must be signed in to change notification settings - Fork 0
Install back‐end Library Crow in Globally in Linux
Crow relies heavily on asynchronous networking behind the scenes, it requires one specific C++ networking library called ASIO to function.
Here is exactly how to install Crow globally on your Debian system:
You already have CMake and OpenSSL from our previous steps. You just need to grab ASIO from the Debian repository. Run this:
sudo apt update
sudo apt install libasio-dev
Just like we did with CPR, we will download the source code, tell CMake to configure it, and install it into your system's global library folders.
Run these commands one by one in your terminal:
1. Download the Crow source code:
git clone https://github.com/CrowCpp/Crow.git
cd Crow
2. Configure the build: (We are adding flags to turn off examples and tests so it installs almost instantly).
cmake -S . -B build -DCROW_BUILD_EXAMPLES=OFF -DCROW_BUILD_TESTS=OFF
3. Install it globally (requires sudo):
Because Crow is actually a "header-only" library at its core, you don't even need to run a build command! CMake will simply copy the Crow headers and configuration files directly into your system's /usr/local/include folder.
sudo cmake --install build
You can now safely delete the downloaded Crow folder to clean up your workspace.
Now that Crow is globally installed, there is one minor change to how you write your code. You no longer use "crow_all.h". Instead, you use the standard system include brackets with <crow.h>.
Here is your new, ultra-clean template for any folder on your computer:
#include <iostream>
#include <crow.h> // Notice the angle brackets! It pulls from your system now.
int main() {
crow::SimpleApp app;
CROW_ROUTE(app, "/")([](){
return "Hello from my globally installed Crow server!";
});
// Run on port 8080
app.port(8080).multithreaded().run();
}
Because Crow handles multithreading, you just need your -lpthread flag. No CMake required!
g++ main.cpp -o server -lpthread
./server