I'm trying to build a simple echo service with seasocks in c++. I've compiled and installed seasocks into /usr/local/* and it appears the libraries are included just fine, however I'm getting errors starting the server.
This is the example that I'm using:
#include "seasocks/PrintfLogger.h"
#include "seasocks/Server.h"
#include "seasocks/StringUtil.h"
#include "seasocks/WebSocket.h"
#include <cstring>
#include <iostream>
#include <memory>
#include <set>
#include <sstream>
#include <string>
/* Simple server that echo any text or binary WebSocket messages back. */
using namespace seasocks;
class EchoHandler: public WebSocket::Handler {
public:
virtual void onConnect(WebSocket* /*connection*/) {
}
virtual void onData(WebSocket* connection, const uint8_t* data, size_t length) {
connection->send(data, length); // binary
}
virtual void onData(WebSocket* connection, const char* data) {
connection->send(data); // text
}
virtual void onDisconnect(WebSocket* /*connection*/) {
}
};
int main(int /*argc*/, const char* /*argv*/[]) {
std::shared_ptr<Logger> logger(new PrintfLogger(Logger::Level::DEBUG));
Server server(logger);
std::shared_ptr<EchoHandler> handler(new EchoHandler());
server.addWebSocketHandler("/", handler);
server.serve("/dev/null", 8000);
return 0;
}
These are my build errors:
04:40:40 **** Build of configuration Debug for project HSServer ****
make all
Building file: ../src/HSServer.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/HSServer.d" -MT"src/HSServer.o" -o "src/HSServer.o" "../src/HSServer.cpp"
Finished building: ../src/HSServer.cpp
Building target: HSServer
Invoking: GCC C++ Linker
g++ -o "HSServer" ./src/HSServer.o
./src/HSServer.o: In function `main':
/home/xnite/workspace/HSServer/Debug/../src/HSServer.cpp:37: undefined reference to `seasocks::Server::Server(std::shared_ptr<seasocks::Logger>)'
/home/xnite/workspace/HSServer/Debug/../src/HSServer.cpp:39: undefined reference to `seasocks::Server::addWebSocketHandler(char const*, std::shared_ptr<seasocks::WebSocket::Handler>, bool)'
/home/xnite/workspace/HSServer/Debug/../src/HSServer.cpp:40: undefined reference to `seasocks::Server::serve(char const*, int)'
/home/xnite/workspace/HSServer/Debug/../src/HSServer.cpp:37: undefined reference to `seasocks::Server::~Server()'
/home/xnite/workspace/HSServer/Debug/../src/HSServer.cpp:37: undefined reference to `seasocks::Server::~Server()'
collect2: error: ld returned 1 exit status
make: *** [makefile:47: HSServer] Error 1
04:40:45 Build Finished (took 5s.239ms)