1

I am developing an monolithic C++ app that uses the LIBCURL to make some file transfers via SFTP protocol. However, in my app I need always to manually build the static libs of the libcurl and libssh2.

I made an shell script in order to automate the third-libraries generation (i.e., LIBCURL e LIBSSH2). My script looks like this:

# Initially we shall define some important paths definitions

OPENSSL_MYAPP_RELEASE=$HOME/openssl-1.0.2o/release64/lib/
OPENSSL_MYAPP_DEBUG=$HOME/openssl-1.0.2o/debug64/lib
OPENSSL_MYAPP_INCLUDE=$HOME/openssl-1.0.2o/release64/include/
ZLIB_MYAPP_RELEASE=$HOME/zlib/linux64/release/
ZLIB_MYAPP_DEBUG=$HOME/zlib/linux64/debug/
ZLIB_MYAPP_INCLUDE=$HOME/zlib/linux32/include/
SSH2_MYAPP_RELEASE=$HOME/libssh2/build/linux64/release/
SSH2_MYAPP_DEBUG=$HOME/libssh2/build/linux64/debug/

cd $HOME/libssh2
./configure --enable-static --with-libssl-prefix=$OPENSSL_MYAPP_RELEASE \
--disable-debug --prefix=$SSH2_MYAPP_RELEASE && \
make && \
make install

cd $HOME/curl-7.30
./configure --disable-debug --enable-static --disable-shared \
--disable-ldap --without-libidn --with-zlib=$ZLIB_MYAPP_RELEASE \
--with-ssl=$OPENSSL_MYAPP_RELEASE \
--with-libssh2=$SSH2_MYAPP_RELEASE \
--prefix=$HOME/curl-7.30.0/build/linux64/release/ && \
make && \
make install

The static libraries of the LIBSSH2 and LIBCURL are generated sucessfully but when I compile my application by linking my generated LIBSSH2 and LIBCURL I am getting a lot of undefined references in some important LIBSSH2 methods such as libssh2_init().

When I disassembled the generated LIBCURL, with nm -a libcurl.a, I noticed that there are a lot of undefined symbols in the LIBSSH2 methods.

What could be wrong with my generated script? The linker error messages are something like these ones:

easy.c:(.text+0xe8): undefined reference to `libssh2_init'
easy.c:(.text+0x10c): undefined reference to `libssh2_init'
easy.c:(.text+0x223): undefined reference to `libssh2_exit'
ssh.c:(.text+0x4ac): undefined reference to `libssh2_session_block_directions'
ssh.c:(.text+0x4fa): undefined reference to `libssh2_sftp_write'
ssh.c:(.text+0x58a): undefined reference to `libssh2_sftp_read'
ssh.c:(.text+0x5e6): undefined reference to `libssh2_channel_write_ex'
ssh.c:(.text+0x676): undefined reference to `libssh2_channel_read_ex'
ssh.c:(.text+0x960): undefined reference to `libssh2_session_set_blocking'
ssh.c:(.text+0x97a): undefined reference to `libssh2_session_handshake'
ssh.c:(.text+0x9bb): undefined reference to `libssh2_hostkey_hash'
ssh.c:(.text+0xa4e): undefined reference to `libssh2_session_hostkey'
ssh.c:(.text+0xaa9): undefined reference to `libssh2_knownhost_check'
ssh.c:(.text+0xbc5): undefined reference to `libssh2_knownhost_free'
ssh.c:(.text+0xbe5): undefined reference to `libssh2_agent_disconnect'
ssh.c:(.text+0xc05): undefined reference to `libssh2_agent_free'
ssh.c:(.text+0xc37): undefined reference to `libssh2_session_free'
ssh.c:(.text+0xe01): undefined reference to `libssh2_channel_free'
ssh.c:(.text+0xe44): undefined reference to `libssh2_session_disconnect_ex'

Any ideas/suggestions in how to fix the static libraries generation script?

fborges22
  • 313
  • 3
  • 14
  • 1
    Show the linker command. I suspect libcurl.a follows libssh2.a, that is wrong. – 273K Aug 11 '21 at 20:43
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Axalo Aug 11 '21 at 20:58
  • I do not have the linker command in this case because i am building use the configure scripts. Is the --with-libssh2=$SSH2_MYAPP_RELEASE correct for build libcurl with ssh2 support? – fborges22 Aug 12 '21 at 00:07
  • @Axalo No. Not exactly. I think there maybe a bug in the libcurl 7.30 configure script that is preventing libssh2 fully linking. I am still searching the cause. – fborges22 Aug 13 '21 at 13:03
  • 1
    Any solution to this problem? – Imran Jan 03 '22 at 13:41
  • Yes, after I changed the linking order the lib was linked and compiled successfully. – fborges22 Feb 09 '22 at 13:43

0 Answers0