I downloaded and installed the latest libssh2 from their website into the location /usr/src/libssh2-1.4.0
I was trying to build one of the example programs (ssh2.c) that is available in the example directory. When I compiled with make from /usr/src/libssh2-1.4.0/example as
make ssh2
, it compiled and ran quite fine. I then copied the program ssh2.c to a different path (~/Projects/precious/) and issued the command
gcc -g -I/usr/src/libssh2-1.4.0/src -I/usr/src/libssh2-1.4.0/include -I/usr/src/libssh2-1.4.0/src/obj ssh.c -o ssh -lssh2 -ldl -lnsl -lresolv -lcrypto -lssl -lz
When I am trying to run the program, it greets me with the following message
./ssh: symbol lookup error: ./ssh: undefined symbol: libssh2_session_handshake
I also tried to compile it simply as
g++ -g ssh.c -o ssh -lssh2
The response is all the same.
I also tried compiling as
gcc -DHAVE_CONFIG_H -g -O2 -I/usr/src/libssh2-1.4.0/src -I/usr/src/libssh2-1.4.0/include -I/usr/src/libssh2-1.4.0/src/obj -c -o ssh.o ssh.c
libtool --tag=CC --mode=link gcc -g -O2 -o ssh ssh.o /usr/local/lib/libssh2.la
but without any luck. Please suggest
I suspect that your libssh2 package that you’ve built by hand is a different version (probably newer) than the one installed on your system. And your link line is trying to use the one installed on the system, which doesn’t have the
libssh2_session_handshakefunction in it. Try this line:or maybe this one:
The important thing is to get the -L flag pointing to the path where your compiled library is located.