交叉编译:libcurl动态库

需要在海思板子上使用libcurl库,实现访问url,下载http文件功能。

在虚拟机Ubnutu上很简单就可以安装libcurl库。

apt-get install libcurl4-openssl-dev

主要介绍交叉编译的过程。

交叉编译是通过交叉编译器,编译出在对应硬件环境(板子)上执行的库(静态库/动态库)或者二进制文件的过程。

相应的,如果想在Android下运行,需要使用Android的编译器。本次我们不涉及。

本次使用的交叉编译器为:

aarch64-himix100-linux-gcc

libcurl下载:

https://curl.haxx.se/download.html

交叉编译:libcurl动态库_第1张图片

我们选择下载curl-7.65.1版本,如上图红色框中框起的。

交叉编译过程:

解压:

tar -vxf curl-7.65.1.tar.xz

cd curl-7.65.1/

配置脚本如下:

./configure --with-ssl\
	--disable-shared\
	--enable-static\
	--disable-dict\
	--disable-ftp\
	--disable-imap\
	--disable-ldap\
	--disable-ldaps\
	--disable-pop3\
	--disable-proxy\
	--disable-rtsp\
	--disable-smtp\
	--disable-telnet\
	--disable-tftp\
	--disable-zlib\
	--without-ca-bundle\
	--without-gnutls\
	--without-libidn\
	--without-librtmp\
	--without-libssh2\
	--without-nss\
	--without-zlib\
	--enable-shared\
	--enable-static\
	--host=aarch64-himix100-linux\
	CC=aarch64-himix100-linux-gcc --prefix=$PWD/__install

其中:

-with-ssl是支持ssl。一些加密功能需要ssl库的支持,比如https

--enable-shared --enable-static 分别表示编译出动态库和静态库。如果没有配置,make install之后,应该是生成不了动态库的。

--host=aarch64-himix100-linux 表示编译出来的程序,将要运行的平台。这个选项也是需要配置的。而且,该选项还需要在CC选项之前。这一点是需要注意的。

CC=aarch64-himix100-linux-gcc 表示使用aarch64-himix100-linux-gcc编译器。

--prefix=$PWD/__install 表示make install之后,会把编译生成的头文件、库文件以及man文件,放到当前目录下的__install目录下。可以自己修改。

执行完配置文件后,显示刚才配置的具体情况:

configure: amending docs/examples/Makefile
configure: Configured to build curl/libcurl:

  Host setup:   aarch64-himix100-linux-gnu
  Install prefix:   /root/ken/curl-7.65.1/__install
  Compiler: aarch64-himix100-linux-gcc
   CFLAGS:  -Werror-implicit-function-declaration -O2 -Wno-system-headers -pthread
   CPPFLAGS:
   LDFLAGS: 
   LIBS:-lssl -lcrypto

  curl version: 7.65.1
  SSL:  enabled (OpenSSL)
  SSH:  no  (--with-libssh2)
  zlib: no  (--with-zlib)
  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=yes, 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:FILE GOPHER HTTP HTTPS SMB SMBS
  Features: SSL IPv6 UnixSockets AsynchDNS NTLM NTLM_WB TLS-SRP HTTPS-proxy

root@ubuntu:~/ken/curl-7.65.1# 

然后执行:

make && make install 

编译完成后, 会在当前目录下的__install目录下生成编译出的文件。

root@ubuntu:~/ken/curl-7.65.1/__install# ls
bin  include  lib  share
root@ubuntu:~/ken/curl-7.65.1/__install# 

库文件详细情况:

root@ubuntu:~/ken/curl-7.65.1/__install/lib# ls -lh
total 1000K
-rw-r--r-- 1 root root 646K Jun 19 19:54 libcurl.a
-rwxr-xr-x 1 root root  977 Jun 19 19:54 libcurl.la
lrwxrwxrwx 1 root root   16 Jun 19 19:54 libcurl.so -> libcurl.so.4.5.0
lrwxrwxrwx 1 root root   16 Jun 19 19:54 libcurl.so.4 -> libcurl.so.4.5.0
-rwxr-xr-x 1 root root 343K Jun 19 19:54 libcurl.so.4.5.0
drwxr-xr-x 2 root root 4.0K Jun 19 19:54 pkgconfig
root@ubuntu:~/ken/curl-7.65.1/__install/lib# file *
libcurl.a:current ar archive
libcurl.la:   libtool library file, 
libcurl.so:   symbolic link to `libcurl.so.4.5.0' 
libcurl.so.4: symbolic link to `libcurl.so.4.5.0' 
libcurl.so.4.5.0: ELF 64-bit LSB  shared object, ARM aarch64, version 1 (SYSV), dynamically linked, not stripped
pkgconfig:directory 
root@ubuntu:~/ken/curl-7.65.1/__install/lib#

如果在工程中使用了libcurl库,则需要包含libcurl的头文件:

root@ubuntu:~/ken/curl-7.65.1/__install/include# ls
curl
root@ubuntu:~/ken/curl-7.65.1/__install/include/curl# ls
curl.h  curlver.h  easy.h  mprintf.h  multi.h  stdcheaders.h  system.h  typecheck-gcc.h  urlapi.h
root@ubuntu:~/ken/curl-7.65.1/__install/include/curl#

把curl文件夹,拷贝到工程的include目录下即可。

如果在编译过程中,显示找不都ssl库,则需要提前交叉编译ssl库,然后再编译libcurl时,指定ssl库的位置。

查看 configure的帮助文件:

root@ubuntu:~/ken/curl-7.65.1# ./configure --help
`configure' configures curl - to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help  display this help and exit
  --help=shortdisplay options specific to this package
  --help=recursivedisplay the short help of all the included packages
  -V, --version   display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
  --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache  alias for `--cache-file=config.cache'
  -n, --no-create do not create output files
  --srcdir=DIRfind the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX install architecture-independent files in PREFIX
  [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
  [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIRuser executables [EPREFIX/bin]
  --sbindir=DIR   system admin executables [EPREFIX/sbin]
  --libexecdir=DIRprogram executables [EPREFIX/libexec]
  --sysconfdir=DIRread-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIRmodifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR modifiable single-machine data [PREFIX/var]
  --runstatedir=DIR   modifiable per-process data [LOCALSTATEDIR/run]
  --libdir=DIRobject code libraries [EPREFIX/lib]
  --includedir=DIRC header files [PREFIX/include]
  --oldincludedir=DIR C header files for non-gcc [/usr/include]
  --datarootdir=DIR   read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR   read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR   info documentation [DATAROOTDIR/info]
  --localedir=DIR locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIRman documentation [DATAROOTDIR/man]
  --docdir=DIRdocumentation root [DATAROOTDIR/doc/curl]
  --htmldir=DIR   html documentation [DOCDIR]
  --dvidir=DIRdvi documentation [DOCDIR]
  --pdfdir=DIRpdf documentation [DOCDIR]
  --psdir=DIR ps documentation [DOCDIR]

Program names:
  --program-prefix=PREFIXprepend PREFIX to installed program names
  --program-suffix=SUFFIXappend SUFFIX to installed program names
  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names

System types:
  --build=BUILD configure for building on BUILD [guessed]
  --host=HOST   cross-compile to build programs to run on HOST [BUILD]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE   do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-maintainer-mode
	      enable make rules and dependencies not useful (and
	      sometimes confusing) to the casual installer
  --enable-silent-rules   less verbose build output (undo: "make V=1")
  --disable-silent-rules  verbose build output (undo: "make V=0")
  --enable-debug  Enable debug build options
  --disable-debug Disable debug build options
  --enable-optimize   Enable compiler optimizations
  --disable-optimize  Disable compiler optimizations
  --enable-warnings   Enable strict compiler warnings
  --disable-warnings  Disable strict compiler warnings
  --enable-werror Enable compiler warnings as errors
  --disable-werrorDisable compiler warnings as errors
  --enable-curldebug  Enable curl debug memory tracking
  --disable-curldebug Disable curl debug memory tracking
  --enable-symbol-hiding  Enable hiding of library internal symbols
  --disable-symbol-hiding Disable hiding of library internal symbols
  --enable-hidden-symbols To be deprecated, use --enable-symbol-hiding
  --disable-hidden-symbols
  To be deprecated, use --disable-symbol-hiding
  --enable-ares[=PATH]Enable c-ares for DNS lookups
  --disable-ares  Disable c-ares for DNS lookups
  --disable-rtdisable dependency on -lrt
  --enable-code-coverage  Provide code coverage
  --enable-dependency-tracking
  do not reject slow dependency extractors
  --disable-dependency-tracking
  speeds up one-time build
  --disable-largefile omit support for large files
  --enable-shared[=PKGS]  build shared libraries [default=yes]
  --enable-static[=PKGS]  build static libraries [default=yes]
  --enable-fast-install[=PKGS]
  optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --enable-http   Enable HTTP support
  --disable-http  Disable HTTP support
  --enable-ftpEnable FTP support
  --disable-ftp   Disable FTP support
  --enable-file   Enable FILE support
  --disable-file  Disable FILE support
  --enable-ldap   Enable LDAP support
  --disable-ldap  Disable LDAP support
  --enable-ldaps  Enable LDAPS support
  --disable-ldaps Disable LDAPS support
  --enable-rtsp   Enable RTSP support
  --disable-rtsp  Disable RTSP support
  --enable-proxy  Enable proxy support
  --disable-proxy Disable proxy support
  --enable-dict   Enable DICT support
  --disable-dict  Disable DICT support
  --enable-telnet Enable TELNET support
  --disable-telnetDisable TELNET support
  --enable-tftp   Enable TFTP support
  --disable-tftp  Disable TFTP support
  --enable-pop3   Enable POP3 support
  --disable-pop3  Disable POP3 support
  --enable-imap   Enable IMAP support
  --disable-imap  Disable IMAP support
  --enable-smbEnable SMB/CIFS support
  --disable-smb   Disable SMB/CIFS support
  --enable-smtp   Enable SMTP support
  --disable-smtp  Disable SMTP support
  --enable-gopher Enable Gopher support
  --disable-gopherDisable Gopher support
  --enable-manual Enable built-in manual
  --disable-manualDisable built-in manual
  --enable-libcurl-option Enable --libcurl C code generation support
  --disable-libcurl-option
  Disable --libcurl C code generation support
  --enable-libgcc use libgcc when linking
  --enable-ipv6   Enable IPv6 (with IPv4) support
  --disable-ipv6  Disable IPv6 support
  --enable-openssl-auto-load-config
  Enable automatic loading of OpenSSL configuration
  --disable-openssl-auto-load-config
  Disable automatic loading of OpenSSL configuration
  --enable-versioned-symbols
  Enable versioned symbols in shared library
  --disable-versioned-symbols
  Disable versioned symbols in shared library
  --enable-threaded-resolver
  Enable threaded resolver
  --disable-threaded-resolver
  Disable threaded resolver
  --enable-pthreads   Enable POSIX threads (default for threaded resolver)
  --disable-pthreads  Disable POSIX threads
  --enable-verboseEnable verbose strings
  --disable-verbose   Disable verbose strings
  --enable-sspi   Enable SSPI
  --disable-sspi  Disable SSPI
  --enable-crypto-authEnable cryptographic authentication
  --disable-crypto-auth   Disable cryptographic authentication
  --enable-ntlm-wb[=FILE] Enable NTLM delegation to winbind's ntlm_auth
			      helper, where FILE is ntlm_auth's absolute filename
			      (default: /usr/bin/ntlm_auth)
  --disable-ntlm-wb   Disable NTLM delegation to winbind's ntlm_auth
  helper
  --enable-tls-srpEnable TLS-SRP authentication
  --disable-tls-srp   Disable TLS-SRP authentication
  --enable-unix-sockets   Enable Unix domain sockets
  --disable-unix-sockets  Disable Unix domain sockets
  --enable-cookiesEnable cookies support
  --disable-cookies   Disable cookies support
  --enable-alt-svcEnable alt-svc support
  --disable-alt-svc   Disable alt-svc support

Optional Packages:
  --with-PACKAGE[=ARG]use PACKAGE [ARG=yes]
  --without-PACKAGE   do not use PACKAGE (same as --with-PACKAGE=no)
  --with-pic[=PKGS]   try to use only PIC/non-PIC objects [default=use
  both]
  --with-aix-soname=aix|svr4|both
  shared library versioning (aka "SONAME") variant to
  provide on AIX, [default=aix].
  --with-gnu-ld   assume the C compiler uses GNU ld [default=no]
  --with-sysroot[=DIR]Search for dependent libraries within DIR (or the
  compiler's sysroot if not specified).
  --with-zlib=PATHsearch for zlib in PATH
  --without-zlib  disable use of zlib
  --with-brotli=PATH  Where to look for brotli, PATH points to the BROTLI
  installation; when possible, set the PKG_CONFIG_PATH
  environment variable instead of using this option
  --without-brotlidisable BROTLI
  --with-ldap-lib=libname Specify name of ldap lib file
  --with-lber-lib=libname Specify name of lber lib file
  --with-gssapi-includes=DIR
  Specify location of GSS-API headers
  --with-gssapi-libs=DIR  Specify location of GSS-API libs
  --with-gssapi=DIR   Where to look for GSS-API
  --with-default-ssl-backend=NAME
  Use NAME as default SSL backend
  --without-default-ssl-backend
  Use implicit default SSL backend
  --with-winssl   enable Windows native SSL/TLS
  --without-winssldisable Windows native SSL/TLS
  --with-schannel enable Windows native SSL/TLS
  --without-schannel  disable Windows native SSL/TLS
  --with-darwinsslenable Apple OS native SSL/TLS
  --without-darwinssl disable Apple OS native SSL/TLS
  --with-secure-transport enable Apple OS native SSL/TLS
  --without-secure-transport
  disable Apple OS native SSL/TLS
  --with-amissl   enable Amiga native SSL/TLS (AmiSSL)
  --without-amissldisable Amiga native SSL/TLS (AmiSSL)
  --with-ssl=PATH Where to look for OpenSSL, PATH points to the SSL
  installation (default: /usr/local/ssl); when
  possible, set the PKG_CONFIG_PATH environment
  variable instead of using this option
  --without-ssl   disable OpenSSL
  --with-egd-socket=FILE  Entropy Gathering Daemon socket pathname
  --with-random=FILE  read randomness from FILE (default=/dev/urandom)
  --with-gnutls=PATH  where to look for GnuTLS, PATH points to the
  installation root
  --without-gnutlsdisable GnuTLS detection
  --with-mbedtls=PATH where to look for mbedTLS, PATH points to the
  installation root
  --without-mbedtls   disable mbedTLS detection
  --with-cyassl=PATH  where to look for CyaSSL, PATH points to the
  installation root (default: system lib default)
  --without-cyassldisable CyaSSL detection
  --with-wolfssl=PATH where to look for WolfSSL, PATH points to the
  installation root (default: system lib default)
  --without-wolfssl   disable WolfSSL detection
  --with-mesalink=PATHwhere to look for MesaLink, PATH points to the
  installation root
  --without-mesalink  disable MesaLink detection
  --with-nss=PATH where to look for NSS, PATH points to the
  installation root
  --without-nss   disable NSS detection
  --with-ca-bundle=FILE   Path to a file containing CA certificates (example:
  /etc/ca-bundle.crt)
  --without-ca-bundle Don't use a default CA bundle
  --with-ca-path=DIRECTORY
  Path to a directory containing CA certificates
  stored individually, with their filenames in a hash
  format. This option can be used with OpenSSL, GnuTLS
  and PolarSSL backends. Refer to OpenSSL c_rehash for
  details. (example: /etc/certificates)
  --without-ca-path   Don't use a default CA path
  --with-ca-fallback  Use the built in CA store of the SSL library
  --without-ca-fallback   Don't use the built in CA store of the SSL library
  --without-libpsldisable support for libpsl cookie checking
  --with-libmetalink=PATH where to look for libmetalink, PATH points to the
  installation root
  --without-libmetalink   disable libmetalink detection
  --with-libssh2=PATH Where to look for libssh2, PATH points to the
  LIBSSH2 installation; when possible, set the
  PKG_CONFIG_PATH environment variable instead of
  using this option
  --with-libssh2  enable LIBSSH2
  --with-libssh=PATH  Where to look for libssh, PATH points to the LIBSSH
  installation; when possible, set the PKG_CONFIG_PATH
  environment variable instead of using this option
  --with-libssh   enable LIBSSH
  --with-librtmp=PATH Where to look for librtmp, PATH points to the
				      LIBRTMP installation; when possible, set the
				      PKG_CONFIG_PATH environment variable instead of
				      using this option
  --without-librtmp   disable LIBRTMP
  --with-winidn=PATH  enable Windows native IDN
  --without-winidndisable Windows native IDN
  --with-libidn2=PATH Enable libidn2 usage
  --without-libidn2   Disable libidn2 usage
  --with-nghttp2=PATH Enable nghttp2 usage
  --without-nghttp2   Disable nghttp2 usage
  --with-zsh-functions-dir=PATH
  Install zsh completions to PATH
  --without-zsh-functions-dir
  Do not install zsh completions
  --with-fish-functions-dir=PATH
  Install fish completions to PATH
  --without-fish-functions-dir
  Do not install fish completions

Some influential environment variables:
  CC  C compiler command
  CFLAGS  C compiler flags
  LDFLAGS linker flags, e.g. -L if you have libraries in a
  nonstandard directory 
  LIBSlibraries to pass to the linker, e.g. -l
  CPPFLAGS(Objective) C/C++ preprocessor flags, e.g. -I if
  you have headers in a nonstandard directory 
  CPP C preprocessor
  LT_SYS_LIBRARY_PATH
  User-defined run-time library search path.

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to .
root@ubuntu:~/ken/curl-7.65.1# 

可以观察到,添加ssl库路径的话,可以使用:

  --with-ssl=PATH Where to look for OpenSSL, PATH points to the SSL
  installation (default: /usr/local/ssl); when
  possible, set the PKG_CONFIG_PATH environment
  variable instead of using this option

ssl库的交叉编译,请参考我博客的其他帖子

如有错误,欢迎指正。仅供参考。

你可能感兴趣的:(Libcurl,Linux,Linux,嵌入式_交叉编译)