1.编译zlib (貌似在linux上没有用到这个库)
./configure
make
make install
2.编译openssl
我用的是openssl-0.9.8k.tar.gz
chmod 777 config
./config
生成makefile文件后,打开makefile文件,在CFLAG添加-fPIC
make
make install
用到的include和lib会安装到/usr/local/ssl下面
3.编译libssh2
chmod 777 configure
./configure --with-libssl-prefix=/usr/local/ssl
make
这时候会报错,查看错误:
Making all in simple
make[2]: Entering directory `/root/tool/libssh2-1.1/example/simple'
/bin/sh ../../libtool --tag=CC --mode=link gcc -g -O2 -o scp scp.o ../../src/libssh2.la
gcc -g -O2 -o .libs/scp scp.o ../../src/.libs/libssh2.so -Wl,--rpath -Wl,/usr/local/lib
../../src/.libs/libssh2.so: undefined reference to `dlsym'
../../src/.libs/libssh2.so: undefined reference to `dlerror'
../../src/.libs/libssh2.so: undefined reference to `dlopen'
../../src/.libs/libssh2.so: undefined reference to `dlclose'
collect2: ld returned 1 exit status
原因:编译simple时未添加dl库的链接,修改方法:
cd /root/tool/libssh2-1.1/example/simple
vi Makefile
LDFLAGS = -ldl
make
继续回报上述错误,用同样发方法修改,直至编译成功
编译完后会在/usr/local/lib下面生成libssh2.a libssh2.la libssh2.so libssh2.so.1 libssh2.so.1.0.1
编译完成后,会在libssh2-1.1/src下面生成libssh2_config.h文件
cp libssh2_config.h至include