Building libgit2, openssl_stream.c and "error: dereferencing pointer to incomplete type" for BIOs

Building libgit2, openssl_stream.c and "error: dereferencing pointer to incomplete type" for BIOs

我在新安装的 OS、Ubuntu 14.04.1.

上从源构建 Julia
git clone https://github.com/JuliaLang/julia.git 
make -C deps getall
make -j 12

构建 libgit2 时出现 openssl 错误,Julia 的依赖项之一。

错误信息是:

[ 11%] Building C object CMakeFiles/libgit2_clar.dir/src/pathspec.c.o
/home/guo/Github/julia/deps/srccache/libgit2-211e117a0590583a720c53172406f34186c543bd/src/openssl_stream.c: In function ‘bio_create’:
/home/guo/Github/julia/deps/srccache/libgit2-211e117a0590583a720c53172406f34186c543bd/src/openssl_stream.c:159:3: error: dereferencing pointer to incomplete type
  b->init = 1;
   ^
/home/guo/Github/julia/deps/srccache/libgit2-211e117a0590583a720c53172406f34186c543bd/src/openssl_stream.c:160:3: error: dereferencing pointer to incomplete type
  b->num = 0;
   ^
/home/guo/Github/julia/deps/srccache/libgit2-211e117a0590583a720c53172406f34186c543bd/src/openssl_stream.c:161:3: error: dereferencing pointer to incomplete type
  b->ptr = NULL;
   ^
/home/guo/Github/julia/deps/srccache/libgit2-211e117a0590583a720c53172406f34186c543bd/src/openssl_stream.c:162:3: error: dereferencing pointer to incomplete type
  b->flags = 0;
   ^
/home/guo/Github/julia/deps/srccache/libgit2-211e117a0590583a720c53172406f34186c543bd/src/openssl_stream.c: In function ‘bio_destroy’:
/home/guo/Github/julia/deps/srccache/libgit2-211e117a0590583a720c53172406f34186c543bd/src/openssl_stream.c:172:3: error: dereferencing pointer to incomplete type
  b->init = 0;

make VERBOSE=1之后的错误信息是:

guo@dllab:~/Github/libgit2/build$ make  VERBOSE=1
/home/guo/data/software/cmake-3.6.1-Linux-x86_64/bin/cmake -H/home/guo/Github/libgit2 -B/home/guo/Github/libgit2/build --check-build-system CMakeFiles/Makefile.cmake 0
/home/guo/data/software/cmake-3.6.1-Linux-x86_64/bin/cmake -E cmake_progress_start /home/guo/Github/libgit2/build/CMakeFiles /home/guo/Github/libgit2/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/guo/Github/libgit2/build'
make -f CMakeFiles/libgit2_clar.dir/build.make CMakeFiles/libgit2_clar.dir/depend
make[2]: Entering directory `/home/guo/Github/libgit2/build'
cd /home/guo/Github/libgit2/build && /home/guo/data/software/cmake-3.6.1-Linux-x86_64/bin/cmake -E cmake_depends "Unix Makefiles" /home/guo/Github/libgit2 /home/guo/Github/libgit2 /home/guo/Github/libgit2/build /home/guo/Github/libgit2/build /home/guo/Github/libgit2/build/CMakeFiles/libgit2_clar.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/guo/Github/libgit2/build'
make -f CMakeFiles/libgit2_clar.dir/build.make CMakeFiles/libgit2_clar.dir/build
make[2]: Entering directory `/home/guo/Github/libgit2/build'
[  0%] Building C object CMakeFiles/libgit2_clar.dir/src/openssl_stream.c.o
/usr/bin/cc  -DCLAR_FIXTURE_PATH=\"/home/guo/Github/libgit2/tests/resources/\" -DCLAR_RESOURCES=\"\" -DCLAR_TMPDIR=\"libgit2_tests\" -DGIT_ARCH_64 -DGIT_CURL -DGIT_OPENSSL -DGIT_THREADS -DGIT_USE_NSEC -DGIT_USE_STAT_MTIM -DHAVE_FUTIMENS -DHAVE_QSORT_R -DOPENSSL_SHA1 -D_FILE_OFFSET_BITS=64 -I/home/guo/Github/libgit2/src -I/home/guo/Github/libgit2/include -I/usr/local/include -I/home/guo/Github/libgit2/deps/http-parser -I/home/guo/Github/libgit2/tests  -D_GNU_SOURCE -Wall -Wextra  -fvisibility=hidden -fPIC -Wno-missing-field-initializers -Wstrict-aliasing=2 -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-function -g   -o CMakeFiles/libgit2_clar.dir/src/openssl_stream.c.o   -c /home/guo/Github/libgit2/src/openssl_stream.c
/home/guo/Github/libgit2/src/openssl_stream.c: In function ‘bio_create’:
/home/guo/Github/libgit2/src/openssl_stream.c:159:3: error: dereferencing pointer to incomplete type
  b->init = 1;
   ^
/home/guo/Github/libgit2/src/openssl_stream.c:160:3: error: dereferencing pointer to incomplete type
  b->num = 0;
   ^
/home/guo/Github/libgit2/src/openssl_stream.c:161:3: error: dereferencing pointer to incomplete type
  b->ptr = NULL;
   ^
/home/guo/Github/libgit2/src/openssl_stream.c:162:3: error: dereferencing pointer to incomplete type
  b->flags = 0;
   ^
/home/guo/Github/libgit2/src/openssl_stream.c: In function ‘bio_destroy’:
/home/guo/Github/libgit2/src/openssl_stream.c:172:3: error: dereferencing pointer to incomplete type
  b->init = 0;
   ^
/home/guo/Github/libgit2/src/openssl_stream.c:173:3: error: dereferencing pointer to incomplete type
  b->num = 0;
   ^
/home/guo/Github/libgit2/src/openssl_stream.c:174:3: error: dereferencing pointer to incomplete type
  b->ptr = NULL;
   ^
/home/guo/Github/libgit2/src/openssl_stream.c:175:3: error: dereferencing pointer to incomplete type
  b->flags = 0;
   ^
/home/guo/Github/libgit2/src/openssl_stream.c: In function ‘bio_read’:
/home/guo/Github/libgit2/src/openssl_stream.c:182:35: error: dereferencing pointer to incomplete type
  git_stream *io = (git_stream *) b->ptr;
                                   ^
/home/guo/Github/libgit2/src/openssl_stream.c: In function ‘bio_write’:
/home/guo/Github/libgit2/src/openssl_stream.c:188:35: error: dereferencing pointer to incomplete type
  git_stream *io = (git_stream *) b->ptr;
                                   ^
/home/guo/Github/libgit2/src/openssl_stream.c: At top level:
/home/guo/Github/libgit2/src/openssl_stream.c:217:1: error: variable ‘git_stream_bio_method’ has initializer but incomplete type
 static BIO_METHOD git_stream_bio_method = {
 ^
/home/guo/Github/libgit2/src/openssl_stream.c:218:2: warning: excess elements in struct initializer [enabled by default]
  BIO_TYPE_SOURCE_SINK,
  ^
/home/guo/Github/libgit2/src/openssl_stream.c:218:2: warning: (near initialization for ‘git_stream_bio_method’) [enabled by default]
/home/guo/Github/libgit2/src/openssl_stream.c:219:2: warning: excess elements in struct initializer [enabled by default]
  "git_stream",
  ^
/home/guo/Github/libgit2/src/openssl_stream.c:219:2: warning: (near initialization for ‘git_stream_bio_method’) [enabled by default]
/home/guo/Github/libgit2/src/openssl_stream.c:220:2: warning: excess elements in struct initializer [enabled by default]
  bio_write,
  ^
/home/guo/Github/libgit2/src/openssl_stream.c:220:2: warning: (near initialization for ‘git_stream_bio_method’) [enabled by default]
/home/guo/Github/libgit2/src/openssl_stream.c:221:2: warning: excess elements in struct initializer [enabled by default]
  bio_read,
  ^
/home/guo/Github/libgit2/src/openssl_stream.c:221:2: warning: (near initialization for ‘git_stream_bio_method’) [enabled by default]
/home/guo/Github/libgit2/src/openssl_stream.c:222:2: warning: excess elements in struct initializer [enabled by default]
  bio_puts,
  ^
/home/guo/Github/libgit2/src/openssl_stream.c:222:2: warning: (near initialization for ‘git_stream_bio_method’) [enabled by default]
/home/guo/Github/libgit2/src/openssl_stream.c:223:2: warning: excess elements in struct initializer [enabled by default]
  bio_gets,
  ^
/home/guo/Github/libgit2/src/openssl_stream.c:223:2: warning: (near initialization for ‘git_stream_bio_method’) [enabled by default]
/home/guo/Github/libgit2/src/openssl_stream.c:224:2: warning: excess elements in struct initializer [enabled by default]
  bio_ctrl,
  ^
/home/guo/Github/libgit2/src/openssl_stream.c:224:2: warning: (near initialization for ‘git_stream_bio_method’) [enabled by default]
/home/guo/Github/libgit2/src/openssl_stream.c:225:2: warning: excess elements in struct initializer [enabled by default]
  bio_create,
  ^
/home/guo/Github/libgit2/src/openssl_stream.c:225:2: warning: (near initialization for ‘git_stream_bio_method’) [enabled by default]
/home/guo/Github/libgit2/src/openssl_stream.c:227:1: warning: excess elements in struct initializer [enabled by default]
 };
 ^
/home/guo/Github/libgit2/src/openssl_stream.c:227:1: warning: (near initialization for ‘git_stream_bio_method’) [enabled by default]
/home/guo/Github/libgit2/src/openssl_stream.c: In function ‘verify_server_cert’:
/home/guo/Github/libgit2/src/openssl_stream.c:342:4: warning: ‘ASN1_STRING_data’ is deprecated (declared at /usr/local/include/openssl/asn1.h:553) [-Wdeprecated-declarations]
    const char *name = (char *) ASN1_STRING_data(gn->d.ia5);
    ^
/home/guo/Github/libgit2/src/openssl_stream.c:397:4: warning: ‘ASN1_STRING_data’ is deprecated (declared at /usr/local/include/openssl/asn1.h:553) [-Wdeprecated-declarations]
    memcpy(peer_cn, ASN1_STRING_data(str), size);
    ^
/home/guo/Github/libgit2/src/openssl_stream.c: In function ‘openssl_connect’:
/home/guo/Github/libgit2/src/openssl_stream.c:450:5: error: dereferencing pointer to incomplete type
  bio->ptr = st->io;
     ^
make[2]: *** [CMakeFiles/libgit2_clar.dir/src/openssl_stream.c.o] Error 1
make[2]: Leaving directory `/home/guo/Github/libgit2/build'
make[1]: *** [CMakeFiles/libgit2_clar.dir/all] Error 2
make[1]: Leaving directory `/home/guo/Github/libgit2/build'
make: *** [all] Error 2

您需要根据 Julia README.md:

安装 libssl-dev

openssl — needed for HTTPS support in libgit2 on Linux, install via apt-get install libssl-dev or yum install openssl-devel.

因此,为了在 Ubuntu 中安装它,请在终端中发出以下命令:

sudo apt-get install libssl-dev

之后您可以再次尝试重新编译 Julia。

/usr/bin/cc  -DCLAR_FIXTURE_PATH=\"/home/guo/Github/libgit2/tests/resources/\" -DCLAR_RESOURCES=\"\"
-DCLAR_TMPDIR=\"libgit2_tests\" -DGIT_ARCH_64 -DGIT_CURL -DGIT_OPENSSL -DGIT_THREADS
-DGIT_USE_NSEC -DGIT_USE_STAT_MTIM -DHAVE_FUTIMENS -DHAVE_QSORT_R -DOPENSSL_SHA1
-D_FILE_OFFSET_BITS=64 -I/home/guo/Github/libgit2/src -I/home/guo/Github/libgit2/include
-I/usr/local/include -I/home/guo/Github/libgit2/deps/http-parser -I/home/guo/Github/libgit2/tests
-D_GNU_SOURCE -Wall -Wextra -fvisibility=hidden -fPIC -Wno-missing-field-initializers
-Wstrict-aliasing=2 -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-function -g 
-o CMakeFiles/libgit2_clar.dir/src/openssl_stream.c.o   -c /home/guo/Github/libgit2/src/openssl_stream.c
/home/guo/Github/libgit2/src/openssl_stream.c: In function ‘bio_create’:
/home/guo/Github/libgit2/src/openssl_stream.c:159:3: error: dereferencing pointer to incomplete type
  b->init = 1;
...

看来 Julia 是 mis-configured。

根据您的评论,"I have already installed libssl-dev and also built another version openssl from source manually....",您应该会在某处看到一个 -I 选项,类似于 -I /usr/local/ssl/include。如果 OpenSSL 安装在 /usr/local/ssl,则 header 位置为 /usr/local/ssl/include,库位置为 /usr/local/ssl/lib.

您可能应该在 CFLAGS 中包含 -Wl,-rpath,/usr/local/ssl/lib 以确保运行时链接选择正确的 OpenSSL 库。或者,您可能必须使用 LD_LIBRARY_PATH(但使用 RPATH 通常更容易)。

Julia 对于 OpenSSL 的配置没有太多要说的(除了它需要的):

$ cat README.md | grep -B 1 -A 1 -i ssl
- **[cmake]**                   — needed to build `libgit2`.
- **[openssl]**                 — needed for HTTPS support in `libgit2` on Linux, install via `apt-get install libssl-dev` or `yum install openssl-devel`.
- **[pkg-config]**              - needed to build libgit2 correctly, especially for proxy support

--

[libunwind]:    http://www.nongnu.org/libunwind
[openssl]:      https://www.openssl.org
[libssh2]:      https://www.libssh2.org

如果 Julia 是一个 well-behaved 项目并且它支持 CFLAGS,那么这就是您应该做的全部事情:

$ export CFLAGS="-I/usr/local/ssl/include -L/usr/local/ssl/lib -Wl,-rpath,/usr/local/ssl/lib"
$ CFLAGS="$CFLAGS" make -C deps getall
$ CFLAGS="$CFLAGS" make VERBOSE=1

如果有任何 C++ 组件,那么您将要使用:

$ CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" make -C deps getall
$ CFLAGS="$CFLAGS" CXXFLAGS="$CFLAGS" make VERBOSE=1

在大多数情况下,它看起来像是在尊重您的 CFLAGS:

$ CFLAGS="$CFLAGS" make VERBOSE=1
make[1]: Entering directory '/Users/jwalton/julia/deps'
...
echo make -C build/openblas-12ab1804b6ebcd38b26960d65d254314d8bc33d6/ CC="clang  -mmacosx-version-min=10.6 -m64" FC="gfortran -m64" RANLIB="ranlib" FFLAGS=" -O2 -fPIC" TARGET= BINARY=64 USE_THREAD=1 GEMM_MULTITHREADING_THRESHOLD=50 NUM_THREADS=16 NO_AFFINITY=1 DYNAMIC_ARCH=1 INTERFACE64=1 SYMBOLSUFFIX="64_" LIBPREFIX="libopenblas64_" OBJCONV=/Users/jwalton/julia/deps/build/objconv/objconv MAKE_NB_JOBS=0 # echo first, so we only print the error message below in a failure case
make -C build/openblas-12ab1804b6ebcd38b26960d65d254314d8bc33d6/ CC=clang  -mmacosx-version-min=10.6 -m64 FC=gfortran -m64 RANLIB=ranlib FFLAGS= -O2 -fPIC TARGET= BINARY=64 USE_THREAD=1 GEMM_MULTITHREADING_THRESHOLD=50 NUM_THREADS=16 NO_AFFINITY=1 DYNAMIC_ARCH=1 INTERFACE64=1 SYMBOLSUFFIX=64_ LIBPREFIX=libopenblas64_ OBJCONV=/Users/jwalton/julia/deps/build/objconv/objconv MAKE_NB_JOBS=0
make[2]: Entering directory '/Users/jwalton/julia/deps/build/openblas-12ab1804b6ebcd38b26960d65d254314d8bc33d6'
make[3]: Entering directory '/Users/jwalton/julia/deps/build/openblas-12ab1804b6ebcd38b26960d65d254314d8bc33d6/interface'
clang  -mmacosx-version-min=10.6 -m64 -I/usr/local/ssl/include -L/usr/local/ssl/lib -Wl,-rpath,/usr/local/ssl/lib -O2 -DMAX_STACK_ALLOC=2048 -DEXPRECISION -Wall -m64 -DF_INTERFACE_GFORT  -fPIC -DDYNAMIC_ARCH -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=16 -DASMNAME=_ -DASMFNAME=__ -DNAME=_ -DCNAME= -DCHAR_NAME=\"_\" -DCHAR_CNAME=\"\" -DNO_AFFINITY -I. -O2 -DMAX_STACK_ALLOC=2048 -DEXPRECISION -Wall -m64 -DF_INTERFACE_GFORT  -fPIC -DDYNAMIC_ARCH -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=16 -DASMNAME=_saxpy -DASMFNAME=_saxpy_ -DNAME=saxpy_ -DCNAME=saxpy -DCHAR_NAME=\"saxpy_\" -DCHAR_CNAME=\"saxpy\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c axpy.c -o saxpy.o
clang: warning: -Wl,-rpath,/usr/local/ssl/lib: 'linker' input unused
clang: warning: argument unused during compilation: '-L/usr/local/ssl/lib'
In file included from <built-in>:320:
<command line>:22:9: warning: 'ASMNAME' macro redefined [-Wmacro-redefined]
#define ASMNAME _saxpy
        ^

我不知道其他 Julia 问题,例如 'ASMNAME' macro redefined。我猜(这纯粹是一个猜测),因为我正在 OS X 上测试它,但没有真正的支持(RANLIB="ranlib" 是一个赠品,有些东西是错误的,因为 OS X 使用 Apple 的 libtool,而不是 ranlib).