使用Seasocks Echo服务器构建错误
Build error with seasocks echo server
我正在尝试在C 中建立一个简单的回声服务。我已经编译并安装了seasocks到/usr/local/*中,看来库的包含在内,但是我遇到了启动服务器的错误。
这是我正在使用的示例:
#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;
}
这些是我的构建错误:
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)
您必须链接库。对于ex-
g -o myfile objfilea.o objfileb.o -llibname
libname这是库的名称。对于Linux中的EX-对于库libfoo。因此,您只会写-lfoo。但是在Windows中,它将是foo.lib。您可能必须使用-l ‹path_to_dir›在-l或-l之后没有任何空间才能找到文件。
如果使用IDE,请根据IDE在其他图书馆目录下指定它。
相关文章:
- Agora.io 虚幻引擎插件构建错误
- 尝试将 boost::stacktrace 添加到 CMake 项目时出现构建错误
- Arch Linux.AUR 包 mysql 不能用 makepkg 构建.错误:构建 () 中出现故障
- 组件上的虚幻引擎可蓝图UFUNCTION会导致构建错误
- 尝试构建 xerces c++ 解析器。Netbeans 和命令行构建错误未定义对"xercesc_3_2..."的引用
- pair的两个构造函数几乎相同,为什么不生成构建错误?
- 发生 Qt5.11 应用插件构建错误:信号和插槽参数不兼容
- Visual Studio 2017 中的 Tesseract 3.05 构建错误
- Eclipse 构建错误在默认的 hello world 上
- C++ CMake 构建错误:未定义对"boost::throw_exception(std::exception const&)"的引用
- 在 solaris 上增加 1.64 构建错误
- xgboost 构建错误:参数包未扩展为"..":
- 使用GCC 4.8构建错误:数组用作初始化器
- 编译 Java TD 客户端时出现构建错误
- 如何修复安卓工作室中的NDK构建错误
- C++ Cassandra 构建错误
- 我在 MinGW 和 VS 代码"g++ not recognized as a cmdlet..."时遇到构建错误
- Microsoft Visual Studio 2008,版本9.0.30739.1 SP,DLL构建错误
- 使用PPConsul(C 的领事客户端)构建错误的C 项目
- WURFL nginx 构建错误