This site uses cookies for functional purposes. To continue please read and agree to our Data Privacy.

By closing this message, you consent to our use of cookies on this device.

Crosscompile Guide: cURL Library for FTP / SMTP

libcurl - the multiprotocol file transfer library

libcurl is a free and easy-to-use client-side URL transfer library, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP.

libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user + password authentication (Basic, Digest, NTLM, Negotiate, Kerberos), file transfer resume, http proxy tunneling and more!

libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, macOS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS and more...

libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported, fast, thoroughly documented and is already used by many known, big and successful companies.

cURL and libcurl are licensed under a MIT/X derivate license, see License information

Why to build it

libcurl is already included in AXC F 2152 Firmware 1.1.0 with some features:

admin@axcf2152:~$ curl --version
curl 7.50.1 (arm-pxc-linux-gnueabi) libcurl/7.50.1 GnuTLS/3.5.3 zlib/1.2.8
Protocols: file ftp ftps http https 
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets 

But there's a lot more features and protocols that can be added.

Here's how you build it with these features additional included:

OpenSSL TLS (https) support
zlib Automatic "deflate" decompression

How to build it

  1. download latest source by git clone https://github.com/curl/curl.git
  2. execute source /opt/pxc/current/environment* to load PLCnext environment variables. (SDK path is usually /opt/pxc/2.2.1/)
  3. change to the curl directory: cd curl-master/
  4. execute autoreconf -i to go into developer mode
  5. execute autoconf configure.ac to generate configure script
  6. execute ./configure $CONFIGURE_FLAGS --prefix=YourInstallDirectory to generate files for PLCnext toolchain; Install folder example: --prefix=/home/XXX/Install

    configure:              Configured to build curl/libcurl:
    
    curl version:           7.60.0-DEV
    Host setup:             arm-pxc-linux-gnueabi
    Install prefix:         /home/XXX/Install
    Compiler:               arm-pxc-linux-gnueabi-gcc  -march=armv7-a -mthumb -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/home/ima/PLCnext/SDK/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi
    SSL support:            enabled (OpenSSL)
    SSH support:            no      (--with-libssh2)
    zlib support:           enabled
    brotli support:         no      (--with-brotli)
    GSS-API support:        no      (--with-gssapi)
    TLS-SRP support:        enabled
    resolver:               POSIX threaded
    IPv6 support:           enabled
    Unix sockets support:   enabled
    IDN support:            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)
    SSPI support:           no      (--enable-sspi)
    ca cert bundle:         no
    ca cert path:           no
    ca fallback:            no
    LDAP support:           no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
    LDAPS support:          no      (--enable-ldaps)
    RTSP support:           enabled
    RTMP support:           no      (--with-librtmp)
    metalink support:       no      (--with-libmetalink)
    PSL support:            no      (libpsl not found)
    HTTP2 support:          disabled (--with-nghttp2)
    Protocols:              DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP
  7. execute make to compile
  8. execute make install to install binaries to --prefix=folder

TO DO:

Include additional feature support, if necessary

OpenLDAP LDAP support
mbed TLS TLS (https) support
heimdal Support for GSS-API can be provided by the heimdal package and is used to provide the Kerberos and SPNEGO authentication in libcurl.
MIT Kerberos The MIT Kerberos package is also a GSS-API library which can be used to provide support for the Kerberos and SPNEGO authentication in libcurl.
nghttp2 http2 support
c-ares Asynchronous name resolves
libidn Performing the proper IDNA encodings for international domain names to work.
GnuTLS TLS (https) support
NSS TLS (https) support
wolfSSL TLS (https) support
libssh2 SCP and SFTP support
libmetalink Metalink support

Try to build with everything

Note: Will fail without compiling the dependencies first.

./configure $CONFIGURE_FLAGS --prefix=/home/ima/Install/ --with-libssh2 --with-brotli --with-gssapi --with-libidn2 --enable-sspi --enable-ldap --enable-ldaps --with-librtmp --with-libmetalink --with-nghttp2

For SCP and SFTP support --with-libssh2

  1. clone libssh2 from git:
    git clone https://github.com/libssh2/libssh2.git

  2. compile libssh2

    source /opt/pxc/current/environment* 
    ./buildconf
    ./configure $CONFIGURE_FLAGS --prefix=/home/XXX/Install/
    make
    make install
  3. Compile cURL and add libssh support

    ./configure $CONFIGURE_FLAGS --prefix=/home/XXX/Install/ --with-libssh2=/home/XXX/Install/
    make && make install
    ...
    SSH support:      enabled (libSSH2)
    zlib support:     enabled
    ...
    PSL support:      no      (libpsl not found)
    HTTP2 support:    disabled (--with-nghttp2)
    Protocols:        DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SCP SFTP SMB SMBS SMTP SMTPS TELNET TFTP

cURL after our own compile

  1. Copy the the contents from /home/XXX/Install/ to the PLC at /usr/local/
  2. Execute sudo ldconfig
admin@axcf2152:/usr/local/bin# ./curl --version
curl 7.61.1-DEV (arm-pxc-linux-gnueabi) libcurl/7.61.1-DEV OpenSSL/1.0.2j zlib/1.2.11 libssh2/1.8.1_DEV
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy 

Setting up a PLCnext project with cURL

  1. Create an Eclipse® C++ project
  2. Include headers in project properties:
    "/prefix/includes"
  3. Include libraries in project properties:
    add "curl"
  4. Include libraries path in project properties: add the path "/prefix/lib"
  5. Include cURL header #include "curl/curl.h" into project and compile to test if it compiles fine

Where to find the properties:

  1. right-click the project
  2. choose "Properties" -> "C/C++ Build" -> "Settings"
  3. go to "Cross G++ Compiler" -> "Includes"
  4. go to "Cross G++ Linker" -> "Libraries"

Notes about the APIs

  • Check out this page about the [cURL API] (https://curl.haxx.se/libcurl/c/)
  • There are two APIs included: an "Easy" one and an "Multi"-ASYNC API
  • Watch out!
    Even in the multi API, some functions are blocking and might pose a danger to your RealTime execution.

We have 220 guests and no members online