ARTICLE AD BOX
trying to build a very simple wsserver shell in the cPlusPlus using websPeepee. the Idea is just to accept connections and DO someTing.
they wrote a main.cpp that sets up a websocketpp::server and a Makefile to compile it. The Makefile is standard, just grabbed it from Google AI Overview and don't know if it looks garbage:
CXX = g++ CXXFLAGS = -std=c++17 -Wall -Wextra -O2 LDFLAGS = -lboost_system -lpthread SRC = main.cpp OBJ = $(SRC:.cpp=.o) TARGET = websocket_shell all: $(TARGET) $(TARGET): $(OBJ) $(CXX) $(OBJ) -o $(TARGET) $(LDFLAGS) %.o: %.cpp $(CXX) $(CXXFLAGS) -c $< -o $@ clean: rm -f $(OBJ) $(TARGET)When I run make, instead of building successfully, I get a flood of compiler errors like:
main.cpp: In constructor ‘WebSocketShell::WebSocketShell()’: main.cpp:12:9: error: ‘server’ was not declared in this scope main.cpp:13:45: error: ‘bind’ was not declared in this scope ... main.cpp: In member function ‘void WebSocketShell::on_message(...)’: main.cpp:25:9: error: ‘send_packet’ was not declared in this scopeAfter dozens of errors, the build eventually fails at the linking stage, and then the Makefile prints:
Code
You are an idiot! make: *** [websocket_shell] Error 1This is simply way too much. How do you fix this weird behaviour? Please help.
#include <websocketpp/config/asio_no_tls.hpp> #include <websocketpp/server.hpp> class WebSocketShell { public: WebSocketShell() { server.init_asio(); server.set_message_handler( websocketpp::lib::bind( &WebSocketShell::on_message, this, websocketpp::lib::placeholders::_1, websocketpp::lib::placeholders::_2 ) ); } void on_message(websocketpp::connection_hdl hdl, websocketpp::server<websocketpp::config::asio>::message_ptr msg) { send_packet(hdl, "hello"); // ← this function does not exist } private: websocketpp::server<websocketpp::config::asio> server; // ← required }; int main() { WebSocketShell shell; }