简体   繁体   中英

Cannot cross-compile cURL with OpenSSL support for Windows

I'm trying to cross-compile from Linux (Debian Jessie) for Windows. I've compiled zlib and OpenSSL and the configuring script of cURL did find the libraries however it still said that SSL support was switched off.

This is the build script I used:

# 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

It found the library successfully but then SSL just got disabled because of missing --with-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

Full log: https://paste.kde.org/pwzewydif

To cross compile curl with ssl support, I provided the location directly in CPP_FLAGS and LD_FLAGS rather than providing the path with --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

Check this curl cross compilation script

I struggled a whole week to enable SSL for cURL also. From your configuration log, you need to enable these 2 lines to yes

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

The issue lies in how OpenSSL is built. In my case, I built OpenSSL with adding -fPIC -ldl as below

#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;

If you have errors with the linker undefined reference to 'TLS_DTPREL_VALUE' then please refer to the link https://codeleading.com/article/82492718270/ , the fixes on the link may not work for your OpenSSL, you have to modify it to fit your OpenSSL version.

With my OpenSSL 1.0.2s, the build target is different so need to modify as below:

@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

For cURL v7.48.0, I had to run autoreconf before ./configure , due to some issues with recognizing the -ldl of the configuration.ac.

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

The build script is copied from the Makefile, so if there is any part that isn't available in your environment, just modify it to fit your target.

Final word, while compiling cURL, if you encounter the issue that OpenSSL headers is present but can not be compiled like the example code below . Maybe you don't need to modify the configure.ac , please try autoconf or autoreconf first, then run ./configure with -ldl option like I posted above.

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:     ## -------------------------------------- ##

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM