linux无法编译libevent,一直报错,但是我有装openssl

执行完configure后make,报错:

make
make  all-recursive
make[1]: Entering directory `/libevent-2.0.21-stable'
Making all in .
make[2]: Entering directory `/libevent-2.0.21-stable'
/bin/bash ./libtool --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.  -I./compat -I./include -I./include    -g -O2 -Wall -fno-strict-aliasing -pthread -MT bufferevent_openssl.lo -MD -MP -MF .deps/bufferevent_openssl.Tpo -c -o bufferevent_openssl.lo bufferevent_openssl.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I./compat -I./include -I./include -g -O2 -Wall -fno-strict-aliasing -pthread -MT bufferevent_openssl.lo -MD -MP -MF .deps/bufferevent_openssl.Tpo -c bufferevent_openssl.c  -fPIC -DPIC -o .libs/bufferevent_openssl.o
bufferevent_openssl.c: In function 'bio_bufferevent_new':
bufferevent_openssl.c:106:3: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:107:3: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:108:3: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:109:3: error: dereferencing pointer to incomplete type
bufferevent_openssl.c: In function 'bio_bufferevent_free':
bufferevent_openssl.c:119:7: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:120:8: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:120:19: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:121:22: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:122:4: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:123:4: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:124:4: error: dereferencing pointer to incomplete type
bufferevent_openssl.c: In function 'bio_bufferevent_read':
bufferevent_openssl.c:140:8: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:143:33: error: dereferencing pointer to incomplete type
bufferevent_openssl.c: In function 'bio_bufferevent_write':
bufferevent_openssl.c:159:31: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:165:8: error: dereferencing pointer to incomplete type
bufferevent_openssl.c: In function 'bio_bufferevent_ctrl':
bufferevent_openssl.c:191:31: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:196:10: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:199:4: error: dereferencing pointer to incomplete type
bufferevent_openssl.c: At top level:
bufferevent_openssl.c:228:1: error: variable 'methods_bufferevent' has initializer but incomplete type
bufferevent_openssl.c:229:2: warning: excess elements in struct initializer [enabled by default]
bufferevent_openssl.c:229:2: warning: (near initialization for 'methods_bufferevent') [enabled by default]
bufferevent_openssl.c:229:2: warning: excess elements in struct initializer [enabled by default]
bufferevent_openssl.c:229:2: warning: (near initialization for 'methods_bufferevent') [enabled by default]
bufferevent_openssl.c:230:2: warning: excess elements in struct initializer [enabled by default]
bufferevent_openssl.c:230:2: warning: (near initialization for 'methods_bufferevent') [enabled by default]
bufferevent_openssl.c:231:2: warning: excess elements in struct initializer [enabled by default]
bufferevent_openssl.c:231:2: warning: (near initialization for 'methods_bufferevent') [enabled by default]
bufferevent_openssl.c:232:2: warning: excess elements in struct initializer [enabled by default]
bufferevent_openssl.c:232:2: warning: (near initialization for 'methods_bufferevent') [enabled by default]
bufferevent_openssl.c:233:2: warning: excess elements in struct initializer [enabled by default]
bufferevent_openssl.c:233:2: warning: (near initialization for 'methods_bufferevent') [enabled by default]
bufferevent_openssl.c:234:2: warning: excess elements in struct initializer [enabled by default]
bufferevent_openssl.c:234:2: warning: (near initialization for 'methods_bufferevent') [enabled by default]
bufferevent_openssl.c:235:2: warning: excess elements in struct initializer [enabled by default]
bufferevent_openssl.c:235:2: warning: (near initialization for 'methods_bufferevent') [enabled by default]
bufferevent_openssl.c:236:2: warning: excess elements in struct initializer [enabled by default]
bufferevent_openssl.c:236:2: warning: (near initialization for 'methods_bufferevent') [enabled by default]
bufferevent_openssl.c:237:2: warning: excess elements in struct initializer [enabled by default]
bufferevent_openssl.c:237:2: warning: (near initialization for 'methods_bufferevent') [enabled by default]
bufferevent_openssl.c: In function 'BIO_new_bufferevent':
bufferevent_openssl.c:257:8: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:258:8: error: dereferencing pointer to incomplete type
bufferevent_openssl.c:259:8: error: dereferencing pointer to incomplete type

查看106行文件,是BIO *h

static int
bio_bufferevent_new(BIO *b)
{
    b->init = 0;
    b->num = -1;
    b->ptr = NULL; /* We'll be putting the bufferevent in this field.*/
    b->flags = 0;
    return 1;
}

但是我的/usr/include/openssl目录下执行ls,发现是存在bio.h

执行openssl version -a:

OpenSSL 1.1.0g  2 Nov 2017
built on: reproducible build, date unspecified
platform: dist
compiler: cc -DNDEBUG -DOPENSSL_NO_DYNAMIC_ENGINE -DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines-1.1\"" 
OPENSSLDIR: "/usr/local/ssl"
ENGINESDIR: "/usr/local/lib/engines-1.1"

目前就不知道怎么回事了
编译环境是linux,各位给个提示,怎么查问题?

阅读 14.8k
1 个回答

这是 libevent 与 openssl 版本不兼容导致。

一般来说,它们的版本关系是这样的

libevent openssl
2.1.x 1.1
2.0.x 1.0

因此你有两个选择

  1. 使用 libevent 2.1.x 版本,这与你本机的 openssl 1.1 匹配,无需任何修改直接编译即可。
  2. 使用 libevent 2.0.x 版本,你需要安装 openssl 1.0 版本,然后在编译时指定链接版本。

下面针对第二种选择做详细说明,这种方法是通用的,适用于编译其他软件时出现版本不兼容问题。

  1. 首先安装 openssl 1.0 版本,注意需要头文件。你可以选择从源码安装,或使用操作系统的仓库下载安装。
    这类安装包通常带有 "*-dev" 字样,比如 centos 发行版可能是这样的

    yum install openssl-devel-1.0xxx
  2. openssl 安装完成后,会有一个 pkgconfig/ 目录,实际路径取决于你上一步的操作,一般位于 /usr/lib/usr/local/lib 下。
    这里我们假设是 /usr/local/lib/openssl-1.0/pkgconfig/, 你需要将它设置成 PKG_CONFIG_PATH 的环境变量值,如

    export PKG_CONFIG_PATH=/usr/local/lib/openssl-1.0/pkgconfig/ 
  3. 切换到 libevent 源码目录,把 openssl 头文件路径,及库文件路径加入 configure 配置变量,如

    ./configure   CFLAGS="$(pkg-config --cflags openssl)"   LDFLAGS="$(pkg-config --libs openssl)"
  4. 清除原内容,并重新编译即可

    make clean
    make -j8
推荐问题
宣传栏