为什么websockets.c的libonsion示例给出错误“如果没有编译gnutls,则无法计算SHA1!”

时间:2017-08-21 08:45:59

标签: c websocket gnutls

我正在尝试运行libonion(https://github.com/davidmoreno/onion/tree/master/examples/websockets)的websockets.c示例。但是,当我运行它时,它会出现此错误。

“[ERROR codecs.c:389]如果没有编译gnutls,则无法计算SHA1!现在正在中止”

其他例子运行正常。

我正在编译:

$ gcc -o muz websockets.c -I $ ONION_DIR / src / -L $ ONION_DIR / src / onion / -lonion_static -Lpam -Lgnutls -Lgcrypt -lpthread

终端输出如下:

[49CDC700] [2017-08-21 11:26:12] [DEBUG onion.c:216] Ignoring SIGPIPE
[49CDC700] [2017-08-21 11:26:12] [DEBUG poller.c:328] Init thread stuff for poll. Eventfd at 4
[49CDC700] [2017-08-21 11:26:12] [DEBUG poller.c:328] Init thread stuff for poll. Eventfd at 4
[49CDC700] [2017-08-21 11:26:12] [DEBUG onion.c:649] add 0x136a400 listen_point (0x136a470, 0x136a400, (nil))
[49CDC700] [2017-08-21 11:26:12] [DEBUG onion.c:461] Created default HTTP listen port
[49CDC700] [2017-08-21 11:26:12] [DEBUG listen_point.c:192] Trying to listen at (null):8080
[49CDC700] [2017-08-21 11:26:12] [DEBUG listen_point.c:233] Listening to 0.0.0.0:8080, fd 6
[49CDC700] [2017-08-21 11:26:12] [DEBUG onion.c:507] Adding listen point fd 6 to poller
[49CDC700] [2017-08-21 11:26:12] [DEBUG onion.c:515] Start polling / listening 0x136a470, 0x136a400, (nil)
[494F1700] [2017-08-21 11:26:12] [DEBUG poller.c:497] Start polling
[48CF0700] [2017-08-21 11:26:12] [DEBUG poller.c:497] Start polling
[474ED700] [2017-08-21 11:26:12] [DEBUG poller.c:497] Start polling
[47CEE700] [2017-08-21 11:26:12] [DEBUG poller.c:497] Start polling
[484EF700] [2017-08-21 11:26:12] [DEBUG poller.c:497] Start polling
[46CEC700] [2017-08-21 11:26:12] [DEBUG poller.c:497] Start polling
[49CDC700] [2017-08-21 11:26:12] [DEBUG poller.c:497] Start polling
[464EB700] [2017-08-21 11:26:12] [DEBUG poller.c:497] Start polling
[464EB700] [2017-08-21 11:26:26] [DEBUG response.c:104] Recalculating date header
[464EB700] [2017-08-21 11:26:26] [INFO response.c:189] [127.0.0.1] "GET /" 200 501 (Keep-Alive)
[464EB700] [2017-08-21 11:26:26] [DEBUG websocket.c:88] Websockets!
[464EB700] [2017-08-21 11:26:26] [ERROR codecs.c:389] Cant calculate SHA1 if gnutls is not compiled in! Aborting now

1 个答案:

答案 0 :(得分:2)

不需要单独编译示例,它应该与整个项目一起自动编译。例如,如果您位于主程序包目录中,请创建一个干净的目录并从中运行cmake:

mkdir build && cd build
cmake ..

然后查看cmake的输出并确保找到所有第三方库和其他依赖项。对于gnutls,它应如下所示:

-- Found GnuTLS: /usr/lib/libgnutls.so (found version "3.5.13")
-- Found GCrypt: /usr/include (found version "1.7.7")
-- SSL support is compiled in.

如果您收到如下错误消息:

Gnutls or gcrypt not found. SSL support is not compiled in.

,您必须确保已安装libgnutls.so,并且可以在默认搜索路径中找到(例如/usr/lib/)。

修复cmake错误并运行make后,您应该在examples/websockets/websockets中找到该示例。