【问题标题】:Cannot cross-compile cURL with OpenSSL support for Windows无法使用 Windows 的 OpenSSL 支持交叉编译 cURL
【发布时间】:2017-01-22 14:27:34
【问题描述】:

我正在尝试从 Linux (Debian Jessie) 为 Windows 进行交叉编译。我编译了zlibOpenSSL,cURL 的配置脚本确实找到了这些库,但是它仍然说 SSL 支持已关闭。

这是我使用的构建脚本:

# ZLIB
cd /builds
curl -O -J http://www.zlib.net/zlib-1.2.11.tar.gz
tar xf zlib-1.2.11.tar.gz
cd /builds/zlib-1.2.11
CC=x86_64-w64-mingw32-gcc ./configure --prefix=/usr/x86_64-w64-mingw32 --static
make && make install

# OPENSSL
cd /builds
curl -O -J https://www.openssl.org/source/openssl-1.1.0c.tar.gz
tar xf openssl-1.1.0c.tar.gz
cd /builds/openssl-1.1.0c
CROSS_COMPILE="x86_64-w64-mingw32-" ./Configure -DHAVE_STRUCT_TIMESPEC -lz -lws2_32 zlib mingw64 no-shared --prefix=/usr/x86_64-w64-mingw32
make depend
make && make install

# CURL
cd /builds
curl -O -J https://curl.haxx.se/download/curl-7.52.1.tar.gz
cd /builds/curl-7.52.1
./configure --prefix=/usr/x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-optimize --with-ssl=/usr/x86_64-w64-mingw32

它成功找到了该库,但由于缺少--with-ssl,SSL 刚刚被禁用

checking whether to enable Windows native SSL/TLS (Windows native builds only)... no
checking whether to enable Apple OS native SSL/TLS... no
checking for gdi32... yes
configure: PKG_CONFIG_LIBDIR will be set to "/usr/x86_64-w64-mingw32/lib/pkgconfig"
checking for x86_64-w64-mingw32-pkg-config... /usr/bin/pkg-config
checking for openssl options with pkg-config... found
configure: pkg-config: SSL_LIBS: "-lssl -lcrypto "
configure: pkg-config: SSL_LDFLAGS: "-L/usr/x86_64-w64-mingw32/lib "
configure: pkg-config: SSL_CPPFLAGS: "-I/usr/x86_64-w64-mingw32/include "
checking for HMAC_Update in -lcrypto... no
checking for HMAC_Init_ex in -lcrypto... no
checking for ssl_version in -laxtls... no
configure: WARNING: SSL disabled, you will not be able to use HTTPS, FTPS, NTLM and more.
configure: WARNING: Use --with-ssl, --with-gnutls, --with-polarssl, --with-cyassl, --with-nss, --with-axtls, --with-winssl, or --with-darwinssl to address this.
checking default CA cert bundle/path... configure: WARNING: skipped the ca-cert path detection when cross-compiling
no
checking whether to use builtin CA store of SSL library... no

完整日志:https://paste.kde.org/pwzewydif

【问题讨论】:

    标签: windows curl cross-compiling autotools


    【解决方案1】:

    为了交叉编译 curl 支持 ssl,我直接在 CPP_FLAGSLD_FLAGS 中提供了位置,而不是使用 --with-ssl 提供路径:

    export DESTDIR="$CURL_INSTALL_DIR"
    export CPPFLAGS="-I${OPENSSL_INSTALL_DIR}/include -I${ZLIB_INSTALL_DIR}/include"
    export LDFLAGS="-L${OPENSSL_INSTALL_DIR}/lib -L${ZLIB_INSTALL_DIR}/lib"
    export LIBS="-lssl -lcrypto"
    
    CURL_ARGS="--with-ssl --with-zlib --disable-ftp --disable-gopher 
        --disable-file --disable-imap --disable-ldap --disable-ldaps 
        --disable-pop3 --disable-proxy --disable-rtsp --disable-smtp 
        --disable-telnet --disable-tftp --without-gnutls --without-libidn 
        --without-librtmp --disable-dict"
    
    chmod 777 buildconf
    ./buildconf
    ./configure --host="${CROSS_COMPILE}" $CURL_ARGS
    
    make -j16
    make install
    

    查看curl cross compilation script

    【讨论】:

    • 它不起作用,但我发现我可以构建 cURL 7.49.* 但不能 >=7.50.*。这可能是配置脚本的一个错误,我会向作者报告。无论如何感谢您的帮助。
    • 很高兴它适用于 7.49,但我构建 7.50 没有任何问题。*(我测试了 7.50.0)也许问题出在其他地方
    • 最新的7.52.1呢?您正在为哪个平台构建? (顺便说一句,不幸的是,我在构建时对 cURL 本身有一些“未定义的引用”......我会重建 docker 图像再试一次......)
    • 在我将 OpenSSL 降级到 1.0.2 之后,配置就像一个魅力一样......而且我可能需要一份带有共享库的 OpenSSL 副本来解决未定义的引用问题(链接警告)
    【解决方案2】:

    我花了整整一周的时间才为 cURL 启用 SSL。 从您的配置日志中,您需要将这两行启用为yes

    checking for HMAC_Update in -lcrypto... no
    checking for HMAC_Init_ex in -lcrypto... no
    

    问题在于如何构建 OpenSSL。就我而言,我通过添加-fPIC -ldl 来构建 OpenSSL,如下所示

    #For OpenSSL 1.0.2s
    export USING_OPENSSL=./openssl-1.0.2s
    export CROSS_COMPILE_PREFIX=mips-unknown-linux-uclibc-
    export SSL_OPTIONS="enable-ssl-trace enable-shared enable-ssl enable-ssl2 enable-ssl3 enable-ssl3-method enable-
    tls enable-tls1_1 enable-tls1_2 enable-weak-ssl-ciphers enable-unit-test enable-async enable-md2"
    
    cd $USING_OPENSSL && CC=gcc AR=ar RANLIB=ranlib LD=ld ./Configure linux-mips32 -fPIC -ldl --openssldir=$USING_OPENSSL/OPSSL --prefix=$USING_OP
    ENSSL/OPSSL --cross-compile-prefix=$CROSS_COMPILE_PREFIX $SSL_OPTIONS
    
    make -C $USING_OPENSSL;
    make install -C $USING_OPENSSL;
    

    如果链接器undefined reference to 'TLS_DTPREL_VALUE' 有错误,请参考链接https://codeleading.com/article/82492718270/,链接上的修复可能不适用于您的OpenSSL,您必须修改它以适应您的OpenSSL 版本。

    使用我的 OpenSSL 1.0.2s,构建目标不同,因此需要修改如下:

    @echo Patch Makefile
    sed -i -e 's/build_all:.*/build_all: build_libs/g' $USING_OPENSSL/Makefile
    sed -i -e 's/build_libs:.*/build_libs: build_libcrypto build_libssl build_engines openssl.pc/g' $USING_OPENSSL/Makefile
    sed -i -e 's/DIRS=   crypto ssl engines.*/DIRS=  crypto ssl engines/g' $USING_OPENSSL/Makefile
    

    对于 cURL v7.48.0,我必须在 ./configure 之前运行 autoreconf,因为在识别 configuration.ac 的 -ldl 时存在一些问题。

    cd $APP_CURL_DIR && autoreconf && LIBS="-ldl -lpthread" ./configure --prefix=$APP_CURL_DIR/curl --target=$COMPILE_TOOLCHAIN --host=$HOST CC
    =mips-unknown-linux-uclibc-gcc --with-ssl=$USING_OPENSSL/OPSSL --enable-static
    

    构建脚本是从 Makefile 复制的,因此如果有任何部分在您的环境中不可用,只需修改它以适合您的目标。

    最后,在编译 cURL 时,如果您遇到 OpenSSL 标头存在但无法像 example code below 那样编译的问题。也许您不需要修改configure.ac,请先尝试autoconfautoreconf,然后像我上面发布的那样运行带有-ldl 选项的./configure。

    configure: WARNING: pi.h: present but cannot be compiled
         configure: WARNING: pi.h:     check for missing prerequisite headers?
         configure: WARNING: pi.h: see the Autoconf documentation
         configure: WARNING: pi.h:     section "Present But Cannot Be Compiled"
         configure: WARNING: pi.h: proceeding with the compiler's result
         configure: WARNING:     ## -------------------------------------- ##
         configure: WARNING:     ## Report this to bug-example@example.org ##
         configure: WARNING:     ## -------------------------------------- ##
    

    【讨论】:

      猜你喜欢
      • 2014-07-28
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-09
      • 2012-10-15
      相关资源
      最近更新 更多