我正在尝试运行libonion(https://github.com/davidmoreno/onion/tree/master/examples/websockets)的websockets.c示例但是,当我运行它时,它会给出这个错误。
“[ERROR codecs.c:389]如果未在中编译gnutls,则无法计算SHA1“正在中止”
其他的例子运行良好。
我正在编译:
$gcc-o muz websockets.c-I$洋葱目录/src/-L$洋葱目录/src/洋葱/-L ONION静态-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

最佳答案

不需要单独编译示例,它应该与整个项目一起自动编译例如,如果您在主程序包目录中,请创建一个干净的目录并从中运行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中找到示例。

关于c - 为什么libonion的websockets.c示例给出错误“如果未编译gnutls,则无法计算SHA1!”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45792792/

10-16 13:11