`cargo build`报错:`failed to run custom build command for libgit2-sys v0.13.2+1.4.2`

cargo build报错:failed to run custom build command for libgit2-sys v0.13.2+1.4.2

1 问题背景

在使用cargo编译cargo-cache时出现报错:

The following warnings were emitted during compilation:

warning: [email protected]+1.4.2: In file included from libgit2/src/pack.h:21,
warning: [email protected]+1.4.2:                  from libgit2/src/delta.h:10,
warning: [email protected]+1.4.2:                  from libgit2/src/apply.c:18:
warning: [email protected]+1.4.2: libgit2/src/zstream.h:12:10: fatal error: zlib.h: No such file or directory
warning: [email protected]+1.4.2:    12 | #include 
warning: [email protected]+1.4.2:       |          ^~~~~~~~
warning: [email protected]+1.4.2: compilation terminated.
warning: [email protected]+1.4.2: In file included from libgit2/src/attr_file.c:11:
warning: [email protected]+1.4.2: libgit2/src/filebuf.h:14:10: fatal error: zlib.h: No such file or directory
warning: [email protected]+1.4.2:    14 | #include 
warning: [email protected]+1.4.2:       |          ^~~~~~~~
warning: [email protected]+1.4.2: compilation terminated.

error: failed to run custom build command for `libgit2-sys v0.13.2+1.4.2`

Caused by:
  process didn't exit successfully: `/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5908449b9984da5b/build-script-build` (exit status: 1)
  --- stdout
  cargo:rustc-cfg=libgit2_vendored
  libgit2/include/git2/email.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/email.h
  libgit2/include/git2/patch.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/patch.h
  libgit2/include/git2/pack.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/pack.h
  libgit2/include/git2/credential_helpers.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/credential_helpers.h
  libgit2/include/git2/tree.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/tree.h
  libgit2/include/git2/filter.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/filter.h
  libgit2/include/git2/deprecated.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/deprecated.h
  libgit2/include/git2/attr.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/attr.h
  libgit2/include/git2/apply.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/apply.h
  libgit2/include/git2/errors.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/errors.h
  libgit2/include/git2/revparse.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/revparse.h
  libgit2/include/git2/odb.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/odb.h
  libgit2/include/git2/remote.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/remote.h
  libgit2/include/git2/net.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/net.h
  libgit2/include/git2/repository.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/repository.h
  libgit2/include/git2/index.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/index.h
  libgit2/include/git2/sys/email.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/email.h
  libgit2/include/git2/sys/alloc.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/alloc.h
  libgit2/include/git2/sys/filter.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/filter.h
  libgit2/include/git2/sys/remote.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/remote.h
  libgit2/include/git2/sys/repository.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/repository.h
  libgit2/include/git2/sys/index.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/index.h
  libgit2/include/git2/sys/refs.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/refs.h
  libgit2/include/git2/sys/diff.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/diff.h
  libgit2/include/git2/sys/commit_graph.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/commit_graph.h
  libgit2/include/git2/sys/transport.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/transport.h
  libgit2/include/git2/sys/stream.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/stream.h
  libgit2/include/git2/sys/odb_backend.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/odb_backend.h
  libgit2/include/git2/sys/refdb_backend.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/refdb_backend.h
  libgit2/include/git2/sys/path.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/path.h
  libgit2/include/git2/sys/mempack.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/mempack.h
  libgit2/include/git2/sys/hashsig.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/hashsig.h
  libgit2/include/git2/sys/merge.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/merge.h
  libgit2/include/git2/sys/credential.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/credential.h
  libgit2/include/git2/sys/config.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/config.h
  libgit2/include/git2/sys/reflog.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/reflog.h
  libgit2/include/git2/sys/openssl.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/openssl.h
  libgit2/include/git2/sys/cred.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/cred.h
  libgit2/include/git2/sys/commit.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/commit.h
  libgit2/include/git2/sys/midx.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/sys/midx.h
  libgit2/include/git2/refs.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/refs.h
  libgit2/include/git2/refspec.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/refspec.h
  libgit2/include/git2/checkout.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/checkout.h
  libgit2/include/git2/transaction.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/transaction.h
  libgit2/include/git2/mailmap.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/mailmap.h
  libgit2/include/git2/diff.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/diff.h
  libgit2/include/git2/tag.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/tag.h
  libgit2/include/git2/global.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/global.h
  libgit2/include/git2/blob.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/blob.h
  libgit2/include/git2/transport.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/transport.h
  libgit2/include/git2/oid.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/oid.h
  libgit2/include/git2/cert.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/cert.h
  libgit2/include/git2/odb_backend.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/odb_backend.h
  libgit2/include/git2/reset.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/reset.h
  libgit2/include/git2/status.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/status.h
  libgit2/include/git2/signature.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/signature.h
  libgit2/include/git2/message.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/message.h
  libgit2/include/git2/buffer.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/buffer.h
  libgit2/include/git2/describe.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/describe.h
  libgit2/include/git2/strarray.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/strarray.h
  libgit2/include/git2/stdint.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/stdint.h
  libgit2/include/git2/revert.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/revert.h
  libgit2/include/git2/cred_helpers.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/cred_helpers.h
  libgit2/include/git2/ignore.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/ignore.h
  libgit2/include/git2/graph.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/graph.h
  libgit2/include/git2/indexer.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/indexer.h
  libgit2/include/git2/stash.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/stash.h
  libgit2/include/git2/merge.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/merge.h
  libgit2/include/git2/proxy.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/proxy.h
  libgit2/include/git2/credential.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/credential.h
  libgit2/include/git2/config.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/config.h
  libgit2/include/git2/reflog.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/reflog.h
  libgit2/include/git2/branch.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/branch.h
  libgit2/include/git2/version.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/version.h
  libgit2/include/git2/pathspec.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/pathspec.h
  libgit2/include/git2/rebase.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/rebase.h
  libgit2/include/git2/types.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/types.h
  libgit2/include/git2/annotated_commit.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/annotated_commit.h
  libgit2/include/git2/object.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/object.h
  libgit2/include/git2/revwalk.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/revwalk.h
  libgit2/include/git2/refdb.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/refdb.h
  libgit2/include/git2/worktree.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/worktree.h
  libgit2/include/git2/oidarray.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/oidarray.h
  libgit2/include/git2/blame.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/blame.h
  libgit2/include/git2/trace.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/trace.h
  libgit2/include/git2/commit.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/commit.h
  libgit2/include/git2/submodule.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/submodule.h
  libgit2/include/git2/cherrypick.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/cherrypick.h
  libgit2/include/git2/notes.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/notes.h
  libgit2/include/git2/clone.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/clone.h
  libgit2/include/git2/common.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2/common.h
  libgit2/include/git2.h => /home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include/git2.h
  TARGET = Some("x86_64-unknown-linux-gnu")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-gnu")
  CC_x86_64-unknown-linux-gnu = None
  CC_x86_64_unknown_linux_gnu = None
  HOST_CC = None
  CC = None
  CFLAGS_x86_64-unknown-linux-gnu = None
  CFLAGS_x86_64_unknown_linux_gnu = None
  HOST_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include" "-I" "libgit2/src" "-I" "libgit2/deps/http-parser" "-I" "libgit2/deps/pcre" "-fvisibility=hidden" "-DGIT_REGEX_BUILTIN=1" "-DHAVE_STDINT_H=1" "-DHAVE_MEMMOVE=1" "-DNO_RECURSE=1" "-DNEWLINE=10" "-DPOSIX_MALLOC_THRESHOLD=10" "-DLINK_SIZE=2" "-DPARENS_NEST_LIMIT=250" "-DMATCH_LIMIT=10000000" "-DMATCH_LIMIT_RECURSION=MATCH_LIMIT" "-DMAX_NAME_SIZE=32" "-DMAX_NAME_COUNT=10000" "-DSHA1DC_NO_STANDARD_INCLUDES=1" "-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" "-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" "-o" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/build/libgit2/src/alloc.o" "-c" "libgit2/src/alloc.c"
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include" "-I" "libgit2/src" "-I" "libgit2/deps/http-parser" "-I" "libgit2/deps/pcre" "-fvisibility=hidden" "-DGIT_REGEX_BUILTIN=1" "-DHAVE_STDINT_H=1" "-DHAVE_MEMMOVE=1" "-DNO_RECURSE=1" "-DNEWLINE=10" "-DPOSIX_MALLOC_THRESHOLD=10" "-DLINK_SIZE=2" "-DPARENS_NEST_LIMIT=250" "-DMATCH_LIMIT=10000000" "-DMATCH_LIMIT_RECURSION=MATCH_LIMIT" "-DMAX_NAME_SIZE=32" "-DMAX_NAME_COUNT=10000" "-DSHA1DC_NO_STANDARD_INCLUDES=1" "-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" "-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" "-o" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/build/libgit2/src/annotated_commit.o" "-c" "libgit2/src/annotated_commit.c"
  exit status: 0
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include" "-I" "libgit2/src" "-I" "libgit2/deps/http-parser" "-I" "libgit2/deps/pcre" "-fvisibility=hidden" "-DGIT_REGEX_BUILTIN=1" "-DHAVE_STDINT_H=1" "-DHAVE_MEMMOVE=1" "-DNO_RECURSE=1" "-DNEWLINE=10" "-DPOSIX_MALLOC_THRESHOLD=10" "-DLINK_SIZE=2" "-DPARENS_NEST_LIMIT=250" "-DMATCH_LIMIT=10000000" "-DMATCH_LIMIT_RECURSION=MATCH_LIMIT" "-DMAX_NAME_SIZE=32" "-DMAX_NAME_COUNT=10000" "-DSHA1DC_NO_STANDARD_INCLUDES=1" "-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" "-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" "-o" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/build/libgit2/src/apply.o" "-c" "libgit2/src/apply.c"
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include" "-I" "libgit2/src" "-I" "libgit2/deps/http-parser" "-I" "libgit2/deps/pcre" "-fvisibility=hidden" "-DGIT_REGEX_BUILTIN=1" "-DHAVE_STDINT_H=1" "-DHAVE_MEMMOVE=1" "-DNO_RECURSE=1" "-DNEWLINE=10" "-DPOSIX_MALLOC_THRESHOLD=10" "-DLINK_SIZE=2" "-DPARENS_NEST_LIMIT=250" "-DMATCH_LIMIT=10000000" "-DMATCH_LIMIT_RECURSION=MATCH_LIMIT" "-DMAX_NAME_SIZE=32" "-DMAX_NAME_COUNT=10000" "-DSHA1DC_NO_STANDARD_INCLUDES=1" "-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" "-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" "-o" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/build/libgit2/src/attr.o" "-c" "libgit2/src/attr.c"
  exit status: 0
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include" "-I" "libgit2/src" "-I" "libgit2/deps/http-parser" "-I" "libgit2/deps/pcre" "-fvisibility=hidden" "-DGIT_REGEX_BUILTIN=1" "-DHAVE_STDINT_H=1" "-DHAVE_MEMMOVE=1" "-DNO_RECURSE=1" "-DNEWLINE=10" "-DPOSIX_MALLOC_THRESHOLD=10" "-DLINK_SIZE=2" "-DPARENS_NEST_LIMIT=250" "-DMATCH_LIMIT=10000000" "-DMATCH_LIMIT_RECURSION=MATCH_LIMIT" "-DMAX_NAME_SIZE=32" "-DMAX_NAME_COUNT=10000" "-DSHA1DC_NO_STANDARD_INCLUDES=1" "-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" "-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" "-o" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/build/libgit2/src/attr_file.o" "-c" "libgit2/src/attr_file.c"
  cargo:warning=In file included from libgit2/src/pack.h:21,
  cargo:warning=                 from libgit2/src/delta.h:10,
  cargo:warning=                 from libgit2/src/apply.c:18:
  cargo:warning=libgit2/src/zstream.h:12:10: fatal error: zlib.h: No such file or directory
  cargo:warning=   12 | #include 
  cargo:warning=      |          ^~~~~~~~
  cargo:warning=compilation terminated.
  exit status: 1
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include" "-I" "libgit2/src" "-I" "libgit2/deps/http-parser" "-I" "libgit2/deps/pcre" "-fvisibility=hidden" "-DGIT_REGEX_BUILTIN=1" "-DHAVE_STDINT_H=1" "-DHAVE_MEMMOVE=1" "-DNO_RECURSE=1" "-DNEWLINE=10" "-DPOSIX_MALLOC_THRESHOLD=10" "-DLINK_SIZE=2" "-DPARENS_NEST_LIMIT=250" "-DMATCH_LIMIT=10000000" "-DMATCH_LIMIT_RECURSION=MATCH_LIMIT" "-DMAX_NAME_SIZE=32" "-DMAX_NAME_COUNT=10000" "-DSHA1DC_NO_STANDARD_INCLUDES=1" "-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" "-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" "-o" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/build/libgit2/src/attrcache.o" "-c" "libgit2/src/attrcache.c"
  cargo:warning=In file included from libgit2/src/attr_file.c:11:
  cargo:warning=libgit2/src/filebuf.h:14:10: fatal error: zlib.h: No such file or directory
  cargo:warning=   14 | #include 
  cargo:warning=      |          ^~~~~~~~
  cargo:warning=compilation terminated.
  exit status: 1
  exit status: 0
  exit status: 0

  --- stderr


  error occurred: Command "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/include" "-I" "libgit2/src" "-I" "libgit2/deps/http-parser" "-I" "libgit2/deps/pcre" "-fvisibility=hidden" "-DGIT_REGEX_BUILTIN=1" "-DHAVE_STDINT_H=1" "-DHAVE_MEMMOVE=1" "-DNO_RECURSE=1" "-DNEWLINE=10" "-DPOSIX_MALLOC_THRESHOLD=10" "-DLINK_SIZE=2" "-DPARENS_NEST_LIMIT=250" "-DMATCH_LIMIT=10000000" "-DMATCH_LIMIT_RECURSION=MATCH_LIMIT" "-DMAX_NAME_SIZE=32" "-DMAX_NAME_COUNT=10000" "-DSHA1DC_NO_STANDARD_INCLUDES=1" "-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" "-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" "-o" "/home/yann/Github/cargo-cache-0.8.3/target/debug/build/libgit2-sys-5ab9663e3b04c38d/out/build/libgit2/src/apply.o" "-c" "libgit2/src/apply.c" with args "cc" did not execute successfully (status code exit status: 1).


warning: build failed, waiting for other jobs to finish...

2 解决问题

2.1 可能原因1:zlib库缺失

解决方案:安装zlib库即可。

对debian/ubuntu,在命令行执行如下命令:

$ sudo apt-get install zlib1g-dev

2.2 可能原因2:环境变量冲突

由于我已经安装了zlib库,且该头文件没有缺失。在排查了很久的问题后,发现是anaconda/miniconda中安装了gcc,导致cargo build时未调用操作系统的gcc,而是调用了anaconda/miniconda中安装的gcc,最终出现缺失头文件的报错。

检查方法:
输入命令$ which gcc,查看输出是否为/usr/bin/gcc,或者是anaconda/miniconda目录中的gcc。如果是后者,可以考虑用如下方案解决。

解决方案:

  • 方案1:$ conda deactivate退出虚拟环境后,再进行编译。
  • 方案2:不要在anaconda/miniconda中安装编译器gcc。如果已安装,可以通过$ conda uninstall gcc卸载该包。
  • 方案3:将anaconda/miniconda添加的环境变量从PATH中删除,或者移动到PATH末尾。

相似问题:

  • Linking error on OSX
  • How to force Conda to use gcc found at /usr/bin/gcc?

你可能感兴趣的:(rust,cargo,cargo-cache,linux,conda)