clibcurllibssh2

Compiling curl with libssh2: undefined reference to `libssh2_scp_recv2'


In our product we need to have support for SFTP in cURL. I have libssh2 compiling correctly as Shared and Static Libraries. When I try to compile curl, I set the includes and link in the libssh2 and openssl libraries. This is the script that some previous developer set up to run the configure plus the libssh2 additions.

CFLAGS="-I$opensslpath/include/ -I$libssh2path/include/" \
./configure \
--prefix="$curlpath" \
--without-zlib \
--without-ldap \
--without-lber \
--without-libidn \
--with-nghttp2 \
--with-ssl="$opensslpath" \
--with-libssh2="$libssh2path" \
&& make

The output of the configure:

  Install prefix:   /path/to/libs/curl-7.69.1
  Compiler:         gcc
   CFLAGS:          -isystem /path/to/libs/libssh2-1.10.0/include/ -Werror-implicit-function-declaration -O2 -Wno-system-headers
   CPPFLAGS:        -I/path/to/libs/libssh2-1.10.0/include
   LDFLAGS:         -L/path/to/libs/libssh2-1.10.0/lib
   LIBS:            -lssh2 -lssh2 -lssl -lcrypto -lrt

  curl version:     7.69.1
  SSL:              enabled (OpenSSL)
  SSH:              enabled (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:   /etc/pki/tls/certs/ca-bundle.crt
  ca cert path:     no
  ca fallback:      no
  LDAP:             no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
  LDAPS:            no      (--enable-ldaps)
  RTSP:             enabled
  RTMP:             no      (--with-librtmp)
  Metalink:         no      (--with-libmetalink)
  PSL:              no      (libpsl not found)
  Alt-svc:          no      (--enable-alt-svc)
  HTTP2:            disabled (--with-nghttp2)
  HTTP3:            disabled (--with-ngtcp2, --with-quiche)
  ESNI:             no      (--enable-esni)
  Protocols:        DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SCP SFTP SMB SMBS SMTP SMTPS TELNET TFTP
  Features:         SSL IPv6 UnixSockets AsynchDNS NTLM NTLM_WB TLS-SRP HTTPS-proxy

When I make on curl it fails after compiling everything with this error:

  CCLD     curl
../lib/.libs/libcurl.so: undefined reference to `libssh2_scp_recv2'
collect2: ld returned 1 exit status
make[2]: *** [curl] Error 1

I noticed that after the configure runs it lists the LDFLAGS to have the libssh2/lib path so I made that directory and linked all the library files that were built. I had to do the same for openssl and it finds those references.

I am new to building libraries and it's been a few days of being stuck at this point. Nothing seems to be working. If I remove the libssh2 from the build it builds fine but there is no SFTP support. What am I doing wrong?

EDIT: I notice that the LIBS had -lssh2 twice. I manually edited the Makefile and removed one of them and that didn't make a difference. I also moved it after the ssl and crypto libs and still the same result.


Solution

  • Finally got it working. I was compiling libssh2 wrong. Changed the build script for that to do the build the shared library and then do a make && make install. Then when building curl everything works. Still not sure why this is working but it is.

    ./configure \
      --enable-shared \
      --prefix="$libssh2path" \
      --exec-prefix="$libssh2path" \
      --disable-clear-memory \
      --with-libssl-prefix="$opensslpath"
    
    mkdir bin
    cd bin
    cmake -DBUILD_SHARED_LIBS=ON ..
    cmake --build .
    cd ..
    make && make install