Question

I want to know if it is possible to link my application to libssh while cross-compiling with Sourcery toolchain for ARM. My host system is Ubuntu x86_64

:~/c/ssh$ arm-none-linux-gnueabi-gcc ssh.c -o arm `pkg-config --cflags --libs libssh`
cc1: warning: include location "/usr/local/include" is unsafe for cross-compilation [-Wpoison-system-directories]
/home/user/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: library search path "/usr/local/lib" is unsafe for cross-compilation
/usr/local/lib/libssh.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status

My application compile fine with gcc using this command:

gcc ssh.c -o ssh -lssh

Adding the same -lssh flag while cross-compiling result in the following error:

:~/c/ssh$ arm-none-linux-gnueabi-gcc ssh.c -o arm -lssh
ssh.c:2:49: fatal error: libssh/libssh.h: No such file or directory
compilation terminated.
Was it helpful?

Solution

Your first attempt is trying to link the libssh.o from your host environment instead of your target environment. This is because the command "pkg-config --cflags --libs libssh" returns the package configuration of libssh on your host machine.

You will need to obtain or compile up a copy of libssh specifically for the target environment (ARM).

If compiling it yourself (likely your only option, for me at least a quick google did not reveal any suitable pre-built package) then you should specify a separate installation directory, eg. in your home directory somewhere. This will result in separate include and lib dirs, containing the cross compiled libssh, which you can reference from your own compilation commands, eg:

arm-none-linux-gnueabi-gcc -I{includedir} -L{libdir} ssh.c -o arm -lssh

Note that libssh in turn relies on other libraries - openssl and zlib - which you also have to cross-compile.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top