You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译Git 2.37.0时imap-send报OpenSSL未定义引用如何解决

问题场景

为筹备升级gitlab-ee,计划将Git升级至2.37.0版本,源码编译过程中出现如下链接错误:

LINK git-imap-send
imap-send.o: In function `verify_hostname':
/opt/tmp/git-2.37.0/imap-send.c:242: undefined reference to `OPENSSL_sk_num'
/opt/tmp/git-2.37.0/imap-send.c:244: undefined reference to `OPENSSL_sk_value'
/opt/tmp/git-2.37.0/imap-send.c:250: undefined reference to `OPENSSL_sk_pop_free'
/opt/tmp/git-2.37.0/imap-send.c:250: undefined reference to `OPENSSL_sk_pop_free'
imap-send.o: In function `ssl_socket_connect':
/opt/tmp/git-2.37.0/imap-send.c:277: undefined reference to `OPENSSL_init_ssl'
/opt/tmp/git-2.37.0/imap-send.c:278: undefined reference to `OPENSSL_init_ssl'
/opt/tmp/git-2.37.0/imap-send.c:280: undefined reference to `TLS_method'
/opt/tmp/git-2.37.0/imap-send.c:335: undefined reference to `SSL_get1_peer_certificate'
/opt/tmp/git-2.37.0/imap-send.c:293: undefined reference to `SSL_CTX_set_options'
collect2: error: ld returned 1 exit status
make: *** [git-imap-send] Error 1

当前环境已升级OpenSSL到3.0.3版本,版本查询结果:

# openssl version 
OpenSSL 3.0.3 3 May 2022 (Library: OpenSSL 3.0.3 3 May 2022)

OpenSSL安装路径为/usr/local/bin/openssl,已将动态库路径写入/etc/ld.so.conf.d/openssl3.conf配置,编译Git仍然失败。

故障原因

/etc/ld.so.conf.d/下配置的动态库路径仅对程序运行时的库加载生效,编译阶段的链接器不会主动读取该路径搜索依赖。Git的configure脚本默认搜索系统默认路径下的OpenSSL(通常为/usr目录下的1.1.x旧版本),旧版本库不包含OpenSSL 3.0新增的接口符号,因此触发链接阶段的undefined reference错误。

解决步骤
  • 第一步:清理之前编译生成的中间文件和配置缓存,避免旧配置干扰结果
    cd /opt/tmp/git-2.37.0
    make distclean
    
  • 第二步:指定OpenSSL 3.0的安装根目录重新执行配置。当前OpenSSL二进制在/usr/local/bin,对应安装根目录为/usr/local,头文件在/usr/local/include,库文件在/usr/local/lib,执行以下命令:
    ./configure --prefix=/usr/local/git-2.37.0 --with-openssl=/usr/local
    
  • 第三步:确认配置输出中识别到的OpenSSL版本为3.0.3后,执行编译安装:
    make -j$(nproc)
    make install
    
  • 第四步:编译完成后验证结果
    /usr/local/git-2.37.0/bin/git --version
    ldd /usr/local/git-2.37.0/libexec/git-core/git-imap-send | grep libssl
    
    确认输出的libssl路径指向/usr/local下安装的OpenSSL 3.0库路径即可。

如果执行configure时仍然提示找不到OpenSSL,手动指定编译和链接参数后重新配置编译即可:

make distclean
export CFLAGS="-I/usr/local/include"
export LDFLAGS="-L/usr/local/lib -Wl,-rpath=/usr/local/lib"
./configure --prefix=/usr/local/git-2.37.0
make -j$(nproc)
make install

参数中-Wl,-rpath=/usr/local/lib会把动态库搜索路径直接编译进Git二进制文件,避免后续运行时找不到对应版本的OpenSSL库。

内容的提问来源于stack exchange,提问作者InGramViking

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.27 10:12:16