鍍金池/ 問答/Java  Linux  網(wǎng)絡(luò)安全/ linux無法編譯libevent,一直報(bào)錯(cuò),但是我有裝openssl

linux無法編譯libevent,一直報(bào)錯(cuò),但是我有裝openssl

執(zhí)行完configure后make,報(bào)錯(cuò):

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目錄下執(zhí)行l(wèi)s,發(fā)現(xiàn)是存在bio.h

執(zhí)行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"

目前就不知道怎么回事了
編譯環(huán)境是linux,各位給個(gè)提示,怎么查問題?

回答
編輯回答
枕邊人

這是 libevent 與 openssl 版本不兼容導(dǎo)致。

一般來說,它們的版本關(guān)系是這樣的

libevent openssl
2.1.x 1.1
2.0.x 1.0

因此你有兩個(gè)選擇

  1. 使用 libevent 2.1.x 版本,這與你本機(jī)的 openssl 1.1 匹配,無需任何修改直接編譯即可。
  2. 使用 libevent 2.0.x 版本,你需要安裝 openssl 1.0 版本,然后在編譯時(shí)指定鏈接版本。

下面針對(duì)第二種選擇做詳細(xì)說明,這種方法是通用的,適用于編譯其他軟件時(shí)出現(xiàn)版本不兼容問題。

  1. 首先安裝 openssl 1.0 版本,注意需要頭文件。你可以選擇從源碼安裝,或使用操作系統(tǒng)的倉(cāng)庫(kù)下載安裝。
    這類安裝包通常帶有 "*-dev" 字樣,比如 centos 發(fā)行版可能是這樣的

    yum install openssl-devel-1.0xxx
  2. openssl 安裝完成后,會(huì)有一個(gè) pkgconfig/ 目錄,實(shí)際路徑取決于你上一步的操作,一般位于 /usr/lib/usr/local/lib 下。
    這里我們假設(shè)是 /usr/local/lib/openssl-1.0/pkgconfig/, 你需要將它設(shè)置成 PKG_CONFIG_PATH 的環(huán)境變量值,如

    export PKG_CONFIG_PATH=/usr/local/lib/openssl-1.0/pkgconfig/ 
  3. 切換到 libevent 源碼目錄,把 openssl 頭文件路徑,及庫(kù)文件路徑加入 configure 配置變量,如

    ./configure   CFLAGS="$(pkg-config --cflags openssl)"   LDFLAGS="$(pkg-config --libs openssl)"
  4. 清除原內(nèi)容,并重新編譯即可

    make clean
    make -j8
2018年2月19日 22:56