Ideally you'd make your own CMakeLists.txt for your executable, and in it you'd
call add_directory(<path to libssh's CMakeLists.txt>) so that you can get it to
search for the dependencies and set the link lines for you.
A CMake tutorial is bigger than I'm willing to take on here, but an untested
simple starter one could look like this:
cmake_minimum_required(VERSION 3.0.2)
project(sshtest)
find_package(OpenSSL)
add_subdirectory_once("path/to/libssh" libssh)
set (srcs sshtest.c)
add_executable(sshtest ${srcs})
target_link_libraries(sshtest libssh)
-----Original Message-----
From: Thomas Käfer [mailto:[email protected]]
Sent: Friday, September 22, 2017 1:41 PM
To: [email protected]
Subject: Re: static cross-compiling
thanks for the reply jeremy!
Yes I've found this option and was able to generate a libssh.a file.
but how do I use this?
$ gcc sshtest.c libssh.a -o sshtest.x64 -static doesn't look very promising
(see attached log)
2017-09-22 22:33 GMT+02:00 Jeremy Cross <[email protected]>:
> Sure, there's a WITH_STATIC_LIB option on the cmake.
>
> Try something like:
> cmake -DWITH_EXAMPLES=OFF -DBUILD_SHARED_LIBS=OFF -DWITH_STATIC_LIB=ON
> -DOPENSSL_ROOT_DIR="<your path here>"
>
> -----Original Message-----
> From: Thomas Käfer [mailto:[email protected]]
> Sent: Friday, September 22, 2017 1:27 PM
> To: [email protected]
> Subject: Re: static cross-compiling
>
> I tried to recursively (manually..) follow the errors and install the dev
> packages and include the libraries with the "-lname" parameter to my gcc
> line, but this is getting out of hand. It doesn't look like I'll ever reach
> an end:
>
> $ gcc sshtest.c -lssh -lcrypto -lz -lgss -lshishi -ltasn1 -lidn
> -lgcrypt -o sshtest.x64 -static (output see attached file)
>
> there must be some better easier way? I'm more of a java developer and there
> we have maven or other build systems to pull in requirements for building -
> can I use cmake or something else to walk those dependency paths for me
> instead of having to do this manually?
>
> 2017-09-21 23:11 GMT+02:00 Jeremy Cross <[email protected]>:
>> Your output indicates that you are missing symbols during the linking. The
>> symbol names (like BN_new) are from OpenSSL, which would indicate that you
>> are not properly including OpenSSL libraries in your linking. Depending on
>> your configuration there may be other libraries you also need to be linking
>> in...
>>
>> -----Original Message-----
>> From: Thomas Käfer [mailto:[email protected]]
>> Sent: Thursday, September 21, 2017 1:25 PM
>> To: [email protected]
>> Subject: Re: static cross-compiling
>>
>> I'm sorry, I forgot to mention that I did read
>> http://api.libssh.org/master/libssh_linking.html and tried to put "#define
>> LIBSSH_STATIC 1" and "#define LIBSSH_STATIC" before my include libssh line
>> but it didn't seem to make a difference..?
>>
>> Ah. okey. I've found this link now:
>> https://stackoverflow.com/questions/21083052/cross-compiling-for-arm-
>> w hile-linking-to-libssh-libssh-so-file-not-recognized
>>
>> So if that's correct I need to cross-compile libssh and it's dependencies
>> openssl and zlib for arm first, and can then using those prepared arm lib
>> binaries compile a static build of my program. I will try to work on that
>> next. Or have a look "embedded Linux distros like Buildroot, OpenEmbedded or
>> Embedded Debian Project" to see if I find ready made arm binaries I can use?
>>
>> 2017-09-21 19:06 GMT+02:00 Thomas Käfer <[email protected]>:
>>> Hello!
>>>
>>> I would like to write a program that I can cross-compile for Android
>>> and OpenWRT devices, that uses libssh to first talk to ssh servers
>>> and in a later development-stage to each other.
>>>
>>> Sadly, I'm not really too experienced in programming C / C++, so
>>> please bear with me.
>>>
>>> I found this tutorial
>>> http://jensd.be/800/linux/cross-compiling-for-arm-with-ubuntu-16-04-
>>> l t s which with the additional install of the package
>>> "libc6-armel-cross"
>>> enabled me to cross-compile a program that prints "hello world" in a
>>> shell on my android device.
>>>
>>> Next step: After installing the package "libssh-dev" I was able to
>>> use sample code from
>>> http://api.libssh.org/master/libssh_tutor_guided_tour.html
>>> to compile a dynamically linked program that works on my Linux laptop.
>>>
>>> Now the step I have been struggling with for the last few hours is
>>> to compile this sample program that uses libssh in a static manner
>>> (and once that is accomplished doing so using the "arm-linux-gnueabi-gcc"
>>> cross-compiler)
>>>
>>> So I tried:
>>> $ gcc sshtest.c -static -lssh
>>> /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libssh.a(misc.c.o):
>>> In function `ssh_path_expand_tilde':
>>> (.text+0x87d): warning: Using 'getpwnam' in statically linked
>>> applications requires at runtime the shared libraries from the glibc
>>> version used for linking
>>> /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libssh.a(misc.c.o):
>>> In function `ssh_get_user_home_dir':
>>> (.text+0x3a): warning: Using 'getpwuid_r' in statically linked
>>> applications requires at runtime the shared libraries from the glibc
>>> version used for linking ...
>>> /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libssh.a(gssapi.c.o):
>>> In function `ssh_packet_userauth_gssapi_token_client':
>>> (.text+0x1b36): undefined reference to `gss_init_sec_context'
>>> /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libssh.a(gssapi.c.o):
>>> In function `ssh_packet_userauth_gssapi_token_client':
>>> (.text+0x1c20): undefined reference to `gss_get_mic'
>>> collect2: error: ld returned 1 exit status
>>>
>>> Then I downloaded the libssh source package and made a static build
>>> of the library using the ccmake gui to set the static parameter to true.
>>> With this I tried:
>>> $ gcc sshtest.c libssh-0.7.5/build/src/libssh.a -lssh
>>> libssh-0.7.5/build/src/libssh.a(curve25519.c.o): In function
>>> `ssh_curve25519_build_k':
>>> curve25519.c:(.text+0x13a): undefined reference to `BN_new'
>>> curve25519.c:(.text+0x1e9): undefined reference to `BN_bin2bn'
>>> libssh-0.7.5/build/src/libssh.a(dh.c.o): In function `ssh_get_random':
>>> ...
>>> libssh-0.7.5/build/src/libssh.a(bignum.c.o): In function `ssh_print_bignum':
>>> bignum.c:(.text+0x175): undefined reference to `BN_bn2hex'
>>> bignum.c:(.text+0x1dc): undefined reference to `CRYPTO_free'
>>> collect2: error: ld returned 1 exit status
>>>
>>>
>>> Now I'm out of ideas or in other words my googling skills are not
>>> sufficient to find new ones ;) Please help..
>>> Kind regards,
>>> Thomas K.
>>