我安装了libwebsockets,然后我想尝试一下http://martinsikora.com/libwebsockets-simple-http-server教程中的代码。从提供的Gist中复制代码,然后将其粘贴到编辑器中,然后使用gcc -Wall -c "server.c" -lwebsockets
进行编译。我得到以下错误:server.c:115:43: error: ‘libwebsocket_internal_extensions’ undeclared (first use in this function)
和server.c:116:43: error: too many arguments to function ‘libwebsocket_create_context’
.
如何解决这些错误?
检查websocket库的路径是否正确(可以找到该库)
我猜函数libwebsocket_create_context()
改变了它的参数。看一下libwebsockets示例test-server.c:
现在应该是这样的:
/* old Version:
context = libwebsocket_create_context(port, interface, protocols,
libwebsocket_internal_extensions,
cert_path, key_path, -1, -1, opts);
*/
//-- new Version:
struct lws_context_creation_info info;
memset(&info, 0, sizeof info);
info.port = port;
info.iface = interface;
info.protocols = protocols;
info.extensions = libwebsocket_get_internal_extensions();
//if (!use_ssl) {
info.ssl_cert_filepath = NULL;
info.ssl_private_key_filepath = NULL;
//} else {
// info.ssl_cert_filepath = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.pem";
// info.ssl_private_key_filepath = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.key.pem";
//}
info.gid = -1;
info.uid = -1;
info.options = opts;
context = libwebsocket_create_context(&info);
//------
我认为最近,直到v2.0, libwebsockets经历了一些大的重构,从libwebsockets_…lws_……为例。我需要一个c++包装器,如果我找不到更新的,我可以自己写。希望它更稳定,也许v2.0会给我们。