日期:2014-05-16  浏览次数:20607 次

linux如何使用openssl
最近要做一个项目要用到openssl库(Linux里)。无奈,不得不安装openssl了。可是查了好多的资料都是一头雾水,都不知道到底要是怎样才算是安装成功了。我的系统是:redhat,内核是:2.6.32。我下载的是openssl-0.9.8e版本的openssl.我安装的步骤是:
1、tar zxvf openssl-0.9.8e.tar.gz -C /home
2、cd openssl-0.9.8e
3、make clean
4、./config
5、make 
6、make test 
7、make install
以上安装后,我可以在/usr/local中生成一个ssl目录。ssl/include/openssl/*.h(这个目录下全是头文件。)当然在目录/usr/local/ssl下还有:bin certs includ lib man misc private目录,还有openssl.cnf文件。

可是呢!我在/home目录下写test.c文件:
#include<openssl/rsa.h> 
int main()
{
}

我编译:gcc -c test test.c
报错:找不到头文件。
所以我把/usr/local/ssl/include目录下的openssl目录拷贝到了/usr/local/include目录下。
再编译:gcc -c test test.c
就不报错了。

我以为这样就算是安装好了,可是我又测试了一下。我在网上下载了一个加密的程序。
编译:gcc -o rsa-encrypt rsa-encrypt.c 
报错:
undefined reference to 'BN_new'
undefined reference to 'BN_hex2nb'
undefined reference to 'BN_set_word'
undefined reference to 'RSA_new'
undefined reference to 'RSA_print_fp'
........
很多这样的错。我不知道我的openssl是不安装好了。请高手指点一下。

跪拜!

(我个人觉得,要是真的安装好了,在/usr/include目录下就会有openssl目录,当然有相关的头文件。)



------解决方案--------------------
gcc编译的时候加-lssl
链接到相应的库
------解决方案--------------------
ivi /etc/ld.so.conf
添加搜索路径
/usr/local/ssl

运行ldconfig
试试
------解决方案--------------------
sudo apt-get install openssl,一般会自动解决依赖关系(aptitude更好),安装安装的路径在根目录/etc/ssl,/usr/lib/ssl下

./configure ;make ;make install一般默认安装在/user/local下,只安装这个包