我想为我的一个Android应用程序编译curl并生成libcurl.a。我已经编写了以下脚本,用于通过curl配置帮助生成lib。
我已经使用Linux平台交叉编译curl库。
构建脚本.sh文件
#!/bin/bash -e
CURL_VERSION=curl-7.64.1
NDK_TOOLCHAIN_VERSION=4.9
NDK_TARGET_API=21
NDK_ARCHITECTURE=armeabi-v7a
CURRENT_DIRECTORY=$PWD
ZLIB_PREBUILD_PATH=$CURRENT_DIRECTORY/zlib/$NDK_ARCHITECTURE
OPENSSL_PREBUILD_PATH=$CURRENT_DIRECTORY/openssl/$NDK_ARCHITECTURE
LIB_OUTPUT_DIR=$CURRENT_DIRECTORY/curl/$NDK_ARCHITECTURE
mkdir -p $CURRENT_DIRECTORY/curl
cd $CURRENT_DIRECTORY/curl
export ANDROID_NDK=/home/vijay/Desktop/android-ndk-r17c
if [ ! -d "${CURRENT_DIRECTORY}/arm-linux-android" ]; then
$ANDROID_NDK/build/tools/make_standalone_toolchain.py --arch arm --api ${NDK_TARGET_API} --stl gnustl --install-dir ${CURRENT_DIRECTORY}/arm-linux-android
fi
TOOLCHAIN_PATH=${CURRENT_DIRECTORY}/arm-linux-android/bin:${CURRENT_DIRECTORY}/arm-linux-android/sysroot:${CURRENT_DIRECTORY}/arm-linux-android
CURL_SYSROOT=${CURRENT_DIRECTORY}/arm-linux-android/sysroot
CURL_CROSS_COMPILE="arm-linux-androideabi"
CURL_ARCH=armv7
export SYSROOT=$CURL_SYSROOT
export PATH=$TOOLCHAIN_PATH:$PATH
export CROSS_COMPILE=$CURL_CROSS_COMPILE
export CPPFLAGS="-I$ZLIB_PREBUILD_PATH/include -I$OPENSSL_PREBUILD_PATH/include"
export LDFLAGS="-L$PWD/Output -L$ZLIB_PREBUILD_PATH/lib -L$OPENSSL_PREBUILD_PATH/lib"
export AR=${CROSS_COMPILE}-ar
export AS=${CROSS_COMPILE}-as
export LD=${CROSS_COMPILE}-ld
export RANLIB=${CROSS_COMPILE}-ranlib
export CC=${CROSS_COMPILE}-gcc
export NM=${CROSS_COMPILE}-nm
export LIBS="-lssl -lcrypto"
if [ ! -f $CURL_VERSION.tar.gz ]; then
echo "Downloading the $CURL_VERSION.tar.gz from server"
wget http://curl.haxx.se/download/$CURL_VERSION.tar.gz
fi
if [ -f $CURL_VERSION.tar.gz ]; then
if [ -d $CURL_VERSION ]; then
echo "Removing the old $CURL_VERSION dir at '$PWD'"
rm -rf $CURL_VERSION
fi
if [ -d $NDK_ARCHITECTURE ]; then
echo "Removing the old $NDK_ARCHITECTURE dir at '$PWD'"
rm -rf $NDK_ARCHITECTURE
fi
echo "Extracting the $CURL_VERSION.tar.gz file"
tar -xf $CURL_VERSION.tar.gz
cd $CURL_VERSION
echo "Configure the $CURL_VERSION"
./configure --prefix=$PWD/../Output --host=${CROSS_COMPILE} --with-sysroot=$SYSROOT --with-ssl=$OPENSSL_PREBUILD_PATH --with-zlib=$ZLIB_PREBUILD_PATH --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 --enable-ipv6 --without-librtmp --disable-dict --enable-static --disable-shared
echo "Building the $CURL_VERSION"
make
echo "Copy Curl lib and includes to output directory of the $CURL_VERSION"
# Copy openssl lib and includes to output directory
mkdir -p $LIB_OUTPUT_DIR/lib
mkdir $LIB_OUTPUT_DIR/include
cp libcurl.a $LIB_OUTPUT_DIR/lib
cp -LR include $LIB_OUTPUT_DIR/include
cd ..
echo "curl lib and includes available in output directory $LIB_OUTPUT_DIR"
fi
但是在curl编译时出现以下错误
控制台输出
WARNING:__main__:gnustl is deprecated and will be removed in the next release. Please switch to libc++. See https://developer.android.com/ndk/guides/cpp-support.html for more information.
The curl-7.64.1.tar.gz file exist at '/home/vijay/Desktop/MyScript/curl'
Removing the old curl-7.64.1 dir at '/home/vijay/Desktop/MyScript/curl'
Extracting the curl-7.64.1.tar.gz file
Configure the curl-7.64.1
configure: Configured to build curl/libcurl:
Host setup: arm-unknown-linux-androideabi
Install prefix: /home/vijay/Desktop/MyScript/curl/curl-7.64.1/../Output
Compiler: arm-linux-androideabi-gcc
CFLAGS: -Werror-implicit-function-declaration -O2 -Wno-system-headers
CPPFLAGS: -isystem /home/vijay/Desktop/MyScript/zlib/armeabi-v7a/include -isystem /home/vijay/Desktop/MyScript/openssl/armeabi-v7a/include -I/home/vijay/Desktop/MyScript/zlib/armeabi-v7a/include -I/home/vijay/Desktop/MyScript/openssl/armeabi-v7a/include -I/home/vijay/Desktop/MyScript/openssl/armeabi-v7a/include/openssl
LDFLAGS: -L/home/vijay/Desktop/MyScript/curl/Output -L/home/vijay/Desktop/MyScript/zlib/armeabi-v7a/lib -L/home/vijay/Desktop/MyScript/openssl/armeabi-v7a/lib -L/home/vijay/Desktop/MyScript/zlib/armeabi-v7a/lib -L/home/vijay/Desktop/MyScript/openssl/armeabi-v7a/lib
LIBS: -lssl -lcrypto -lz -lssl -lcrypto
curl version: 7.64.1
SSL: enabled (OpenSSL)
SSH: no (--with-libssh2)
zlib: enabled
brotli: no (--with-brotli)
GSS-API: no (--with-gssapi)
TLS-SRP: enabled
resolver: POSIX threaded
IPv6: enabled
Unix sockets: enabled
IDN: no (--with-{libidn2,winidn})
Build libcurl: Shared=no, Static=yes
Built-in manual: enabled
--libcurl option: enabled (--disable-libcurl-option)
Verbose errors: enabled (--disable-verbose)
Code coverage: disabled
SSPI: no (--enable-sspi)
ca cert bundle: no
ca cert path: no
ca fallback: no
LDAP: no (--enable-ldap / --with-ldap-lib / --with-lber-lib)
LDAPS: no (--enable-ldaps)
RTSP: no (--enable-rtsp)
RTMP: no (--with-librtmp)
Metalink: no (--with-libmetalink)
PSL: no (libpsl not found)
Alt-svc: no (--enable-alt-svc)
HTTP2: disabled (--with-nghttp2)
Protocols: HTTP HTTPS SMB SMBS
Features: SSL IPv6 UnixSockets libz AsynchDNS NTLM NTLM_WB TLS-SRP HTTPS-proxy
Building the curl-7.64.1
Making all in lib
make[1]: Entering directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/lib'
make all-am
make[2]: Entering directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/lib'
CC libcurl_la-file.lo
CC libcurl_la-timeval.lo
CC libcurl_la-base64.lo
CC libcurl_la-hostip.lo
CC libcurl_la-progress.lo
CC libcurl_la-formdata.lo
CC libcurl_la-cookie.lo
CC libcurl_la-http.lo
CC libcurl_la-sendf.lo
CC libcurl_la-ftp.lo
CC libcurl_la-url.lo
CC libcurl_la-dict.lo
CC libcurl_la-if2ip.lo
CC libcurl_la-speedcheck.lo
CC libcurl_la-ldap.lo
CC libcurl_la-version.lo
CC libcurl_la-getenv.lo
CC libcurl_la-escape.lo
CC libcurl_la-mprintf.lo
CC libcurl_la-telnet.lo
CC libcurl_la-netrc.lo
CC libcurl_la-getinfo.lo
CC libcurl_la-transfer.lo
CC libcurl_la-strcase.lo
CC libcurl_la-easy.lo
CC libcurl_la-security.lo
CC libcurl_la-curl_fnmatch.lo
CC libcurl_la-fileinfo.lo
CC libcurl_la-ftplistparser.lo
CC libcurl_la-wildcard.lo
CC libcurl_la-krb5.lo
CC libcurl_la-memdebug.lo
CC libcurl_la-http_chunks.lo
CC libcurl_la-strtok.lo
CC libcurl_la-connect.lo
CC libcurl_la-llist.lo
CC libcurl_la-hash.lo
CC libcurl_la-multi.lo
CC libcurl_la-content_encoding.lo
CC libcurl_la-share.lo
CC libcurl_la-http_digest.lo
CC libcurl_la-md4.lo
CC libcurl_la-md5.lo
CC libcurl_la-http_negotiate.lo
CC libcurl_la-inet_pton.lo
CC libcurl_la-strtoofft.lo
CC libcurl_la-strerror.lo
CC libcurl_la-amigaos.lo
CC libcurl_la-hostasyn.lo
CC libcurl_la-hostip4.lo
CC libcurl_la-hostip6.lo
CC libcurl_la-hostsyn.lo
CC libcurl_la-inet_ntop.lo
CC libcurl_la-parsedate.lo
CC libcurl_la-select.lo
CC libcurl_la-tftp.lo
CC libcurl_la-splay.lo
CC libcurl_la-strdup.lo
CC libcurl_la-socks.lo
CC libcurl_la-ssh.lo
CC libcurl_la-ssh-libssh.lo
CC libcurl_la-curl_addrinfo.lo
CC libcurl_la-socks_gssapi.lo
CC libcurl_la-socks_sspi.lo
CC libcurl_la-curl_sspi.lo
CC libcurl_la-slist.lo
CC libcurl_la-nonblock.lo
CC libcurl_la-curl_memrchr.lo
CC libcurl_la-imap.lo
CC libcurl_la-pop3.lo
CC libcurl_la-smtp.lo
CC libcurl_la-pingpong.lo
CC libcurl_la-rtsp.lo
CC libcurl_la-curl_threads.lo
CC libcurl_la-warnless.lo
CC libcurl_la-hmac.lo
CC libcurl_la-curl_rtmp.lo
CC libcurl_la-openldap.lo
CC libcurl_la-curl_gethostname.lo
CC libcurl_la-gopher.lo
CC libcurl_la-idn_win32.lo
CC libcurl_la-http_proxy.lo
CC libcurl_la-non-ascii.lo
CC libcurl_la-asyn-ares.lo
CC libcurl_la-asyn-thread.lo
CC libcurl_la-curl_gssapi.lo
CC libcurl_la-http_ntlm.lo
CC libcurl_la-curl_ntlm_wb.lo
CC libcurl_la-curl_ntlm_core.lo
CC libcurl_la-curl_sasl.lo
CC libcurl_la-rand.lo
CC libcurl_la-curl_multibyte.lo
CC libcurl_la-hostcheck.lo
CC libcurl_la-conncache.lo
CC libcurl_la-pipeline.lo
CC libcurl_la-dotdot.lo
CC libcurl_la-x509asn1.lo
CC libcurl_la-http2.lo
CC libcurl_la-smb.lo
CC libcurl_la-curl_endian.lo
CC libcurl_la-curl_des.lo
CC libcurl_la-system_win32.lo
CC libcurl_la-mime.lo
CC libcurl_la-sha256.lo
CC libcurl_la-setopt.lo
CC libcurl_la-curl_path.lo
CC libcurl_la-curl_ctype.lo
CC libcurl_la-curl_range.lo
CC libcurl_la-psl.lo
CC libcurl_la-doh.lo
CC libcurl_la-urlapi.lo
CC libcurl_la-altsvc.lo
CC vauth/libcurl_la-vauth.lo
CC vauth/libcurl_la-cleartext.lo
CC vauth/libcurl_la-cram.lo
CC vauth/libcurl_la-digest.lo
CC vauth/libcurl_la-digest_sspi.lo
CC vauth/libcurl_la-krb5_gssapi.lo
CC vauth/libcurl_la-krb5_sspi.lo
CC vauth/libcurl_la-ntlm.lo
CC vauth/libcurl_la-ntlm_sspi.lo
CC vauth/libcurl_la-oauth2.lo
CC vauth/libcurl_la-spnego_gssapi.lo
CC vauth/libcurl_la-spnego_sspi.lo
CC vtls/libcurl_la-openssl.lo
CC vtls/libcurl_la-gtls.lo
CC vtls/libcurl_la-vtls.lo
CC vtls/libcurl_la-nss.lo
CC vtls/libcurl_la-polarssl.lo
CC vtls/libcurl_la-polarssl_threadlock.lo
CC vtls/libcurl_la-cyassl.lo
CC vtls/libcurl_la-schannel.lo
CC vtls/libcurl_la-schannel_verify.lo
CC vtls/libcurl_la-sectransp.lo
CC vtls/libcurl_la-gskit.lo
CC vtls/libcurl_la-mbedtls.lo
CC vtls/libcurl_la-mesalink.lo
CCLD libcurl.la
make[2]: Leaving directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/lib'
make[1]: Leaving directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/lib'
Making all in src
make[1]: Entering directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/src'
Making all in ../docs
make[2]: Entering directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/docs'
Making all in .
make[3]: Entering directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/docs'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/docs'
Making all in cmdline-opts
make[3]: Entering directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/docs/cmdline-opts'
make[3]: Nothing to be done for `all'.
make[3]: Leaving directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/docs/cmdline-opts'
make[2]: Leaving directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/docs'
make[2]: Entering directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/src'
CC curl-slist_wc.o
CC curl-tool_binmode.o
CC curl-tool_bname.o
CC curl-tool_cb_dbg.o
CC curl-tool_cb_hdr.o
CC curl-tool_cb_prg.o
CC curl-tool_cb_rea.o
CC curl-tool_cb_see.o
CC curl-tool_cb_wrt.o
CC curl-tool_cfgable.o
CC curl-tool_convert.o
CC curl-tool_dirhie.o
CC curl-tool_doswin.o
CC curl-tool_easysrc.o
CC curl-tool_filetime.o
CC curl-tool_formparse.o
CC curl-tool_getparam.o
CC curl-tool_getpass.o
CC curl-tool_help.o
CC curl-tool_helpers.o
CC curl-tool_homedir.o
CC curl-tool_hugehelp.o
CC curl-tool_libinfo.o
CC curl-tool_main.o
CC curl-tool_metalink.o
CC curl-tool_msgs.o
CC curl-tool_operate.o
CC curl-tool_operhlp.o
CC curl-tool_panykey.o
CC curl-tool_paramhlp.o
CC curl-tool_parsecfg.o
CC curl-tool_strdup.o
CC curl-tool_setopt.o
CC curl-tool_sleep.o
CC curl-tool_urlglob.o
CC curl-tool_util.o
CC curl-tool_vms.o
CC curl-tool_writeout.o
CC curl-tool_xattr.o
CC ../lib/curl-strtoofft.o
CC ../lib/curl-nonblock.o
CC ../lib/curl-warnless.o
CC ../lib/curl-curl_ctype.o
CCLD curl
curl-tool_cb_dbg.o:tool_cb_dbg.c:function tool_debug_cb: error: undefined reference to 'stdout'
curl-tool_cb_dbg.o:tool_cb_dbg.c:function tool_debug_cb: error: undefined reference to 'stderr'
curl-tool_easysrc.o:tool_easysrc.c:function dumpeasysrc: error: undefined reference to 'stdout'
curl-tool_formparse.o:tool_formparse.c:function tool_mime_stdin_read: error: undefined reference to 'stdin'
curl-tool_formparse.o:tool_formparse.c:function tool_mime_stdin_seek: error: undefined reference to 'stdin'
curl-tool_formparse.o:tool_formparse.c:function tool_mime_new_filedata: error: undefined reference to 'stdin'
curl-tool_getparam.o:tool_getparam.c:function getparameter: error: undefined reference to 'stdin'
curl-tool_getparam.o:tool_getparam.c:function getparameter: error: undefined reference to 'stdout'
curl-tool_getpass.o:tool_getpass.c:function getpass_r: error: undefined reference to 'stderr'
curl-tool_hugehelp.o:tool_hugehelp.c:function hugehelp: error: undefined reference to 'stdout'
curl-tool_main.o:tool_main.c:function main: error: undefined reference to 'stderr'
curl-tool_operate.o:tool_operate.c:function operate_do: error: undefined reference to 'stderr'
collect2: error: ld returned 1 exit status
make[2]: *** [curl] Error 1
make[2]: Leaving directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/vijay/Desktop/MyScript/curl/curl-7.64.1/src'
make: *** [all-recursive] Error 1