Subject: Re: libssh2 static linking - undefined reference to <libssh2 functions>

Re: libssh2 static linking - undefined reference to <libssh2 functions>

From: Simone <simoneazzalin_at_adtelecom.es>
Date: Fri, 25 Sep 2020 17:00:17 +0200

I forgot to say that this was a gcc command error, linked libs go after
c src.
s.

On 9/24/20 4:32 PM, Simone wrote:
> Hello again,
>
> I have the same problem after compiling for x86_64. Here is the output
> if I try to compile scp_write.c from the examples:
> *
> **:~/path/to/libssh2-1.9.0/build_x86_64$ gcc -I install/include/ -I
> example/ -L install/lib/ -l:libssh2.a ../example/scp_write.c **
> **/usr/bin/ld: /tmp/ccdrFU90.o: in function `main':**
> **scp_write.c:(.text+0xf1): undefined reference to `libssh2_init'**
> **/usr/bin/ld: scp_write.c:(.text+0x24a): undefined reference to
> `libssh2_session_init_ex'**
> **/usr/bin/ld: scp_write.c:(.text+0x270): undefined reference to
> `libssh2_session_handshake'**
> **/usr/bin/ld: scp_write.c:(.text+0x2b2): undefined reference to
> `libssh2_hostkey_hash'**
> **/usr/bin/ld: scp_write.c:(.text+0x36f): undefined reference to
> `libssh2_userauth_password_ex'**
> **/usr/bin/ld: scp_write.c:(.text+0x3d1): undefined reference to
> `libssh2_userauth_publickey_fromfile_ex'**
> **/usr/bin/ld: scp_write.c:(.text+0x42d): undefined reference to
> `libssh2_scp_send_ex'**
> **/usr/bin/ld: scp_write.c:(.text+0x45d): undefined reference to
> `libssh2_session_last_error'**
> **/usr/bin/ld: scp_write.c:(.text+0x502): undefined reference to
> `libssh2_channel_write_ex'**
> **/usr/bin/ld: scp_write.c:(.text+0x579): undefined reference to
> `libssh2_channel_send_eof'**
> **/usr/bin/ld: scp_write.c:(.text+0x5a8): undefined reference to
> `libssh2_channel_wait_eof'**
> **/usr/bin/ld: scp_write.c:(.text+0x5d7): undefined reference to
> `libssh2_channel_wait_closed'**
> **/usr/bin/ld: scp_write.c:(.text+0x5e6): undefined reference to
> `libssh2_channel_free'**
> **/usr/bin/ld: scp_write.c:(.text+0x617): undefined reference to
> `libssh2_session_disconnect_ex'**
> **/usr/bin/ld: scp_write.c:(.text+0x623): undefined reference to
> `libssh2_session_free'**
> **/usr/bin/ld: scp_write.c:(.text+0x665): undefined reference to
> `libssh2_exit'**
> **collect2: error: ld returned 1 exit status*
>
> Thanks,
> S.
>
> On 9/24/20 3:10 PM, Simone wrote:
>> Hello,
>>
>> I have built libssh2 and its dependencies for aarch64, in such a way
>> to link these libs as static into the final executable.
>>
>> So the dependencies compiled as static libraries are
>>
>> *libassuan.a
>> libcrypto.a
>> libgcrypt.a
>> libgpg-error.a
>> libksba.a
>> libnpth.a
>> libntbtls.a
>> libssl.a
>> libz.a*
>>
>> To test the static linkage I use the following minimal code:
>>
>>     // libssh2_test.c
>>     #include <libssh2.h>
>>
>>     int main(void)
>>     {
>>         LIBSSH2_SESSION *session;
>>         LIBSSH2_CHANNEL *channel;
>>
>>         libssh2_init(0);
>>         session = libssh2_session_init();
>>
>>         libssh2_session_free(session);
>>         libssh2_exit();
>>         return 0;
>>     }
>>
>> But when I try to compile, ld cannot find libssh2 symbols:
>>
>> *aarch64-linux-gnu-gcc -I ../third/include/ ../third/lib/libz.a
>> ../third/lib/libnpth.a ../third/lib/libssl.a ../third/lib/libcrypto.a
>> ../third/lib/libgpg-error.a ../third/lib/libksba.a
>> ../third/lib/libgcrypt.a ../third/lib/libntbtls.a
>> ../third/lib/libassuan.a ../third/lib/libssh2.a libssh2_test.c -o
>> libssh2_test
>> /opt/Xilinx/Vitis/2019.2/gnu/aarch64/lin/aarch64-linux/bin/../lib/gcc/aarch64-linux-gnu/8.2.0/../../../../aarch64-linux-gnu/bin/ld:
>> /tmp/ccSuPNUb.o: in function `main':
>>     libssh2_test.c:(.text+0xc): undefined reference to `libssh2_init'
>> /opt/Xilinx/Vitis/2019.2/gnu/aarch64/lin/aarch64-linux/bin/../lib/gcc/aarch64-linux-gnu/8.2.0/../../../../aarch64-linux-gnu/bin/ld:
>> libssh2_test.c:(.text+0x20): undefined reference to
>> `libssh2_session_init_ex'
>> /opt/Xilinx/Vitis/2019.2/gnu/aarch64/lin/aarch64-linux/bin/../lib/gcc/aarch64-linux-gnu/8.2.0/../../../../aarch64-linux-gnu/bin/ld:
>> libssh2_test.c:(.text+0x2c): undefined reference to
>> `libssh2_session_free'
>> /opt/Xilinx/Vitis/2019.2/gnu/aarch64/lin/aarch64-linux/bin/../lib/gcc/aarch64-linux-gnu/8.2.0/../../../../aarch64-linux-gnu/bin/ld:
>> libssh2_test.c:(.text+0x30): undefined reference to `libssh2_exit'
>>     collect2: error: ld returned 1 exit status*
>>
>> Of course these functions are defined in libssh2.h.
>> libssh2 has been compiled using the following script:
>>
>> *#!/bin/sh
>>
>> host=aarch64
>> target=aarch64-linux-gnu
>> cc=${target}-gcc
>> cpp=${target}-g++
>> ar=${target}-ar
>> cross_path=/opt/Xilinx/Vitis/2019.2/gnu/aarch64/lin/aarch64-linux/bin
>>
>> install_prefix=${PWD}/../../../third/
>>
>> ../configure     --prefix=${install_prefix} \
>>                  --host=${host}  \
>>                  CC=${cross_path}/${cc}  \
>>                  CXX=${cross_path}/${cpp} \
>>                  --with-gnu-ld  \
>> --with-libgpg-error-prefix=${install_prefix} \
>>                  --with-crypto=auto \
>>                  --with-libgcrypt-prefix=${install_prefix} \
>>                  --with-libssl-prefix=${install_prefix} \
>>                  --enable-static \
>>                  --enable-shared
>>
>> if [ $? -eq 0 ]; then
>>     make -j 32
>>     make install
>> fi*
>>
>> Could someone suggest what I have done wrong ?
>> Thanks.
>> S.
>>
>>
>> _______________________________________________
>> libssh2-develhttps://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
>
>
> _______________________________________________
> libssh2-devel https://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2020-09-25