QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2428|回复: 2

openssl编程,出错

[复制链接]
发表于 2007-7-26 18:29:19 | 显示全部楼层 |阅读模式
openssl版本:openssl-0.9.8b-8,我编了一个小程序用来将根CA的证书添加到自己的信息的证书库中,参考了http://www.ibm.com/developerworks/cn/linux/l-openssl.html,编译的时候没错,运行时出现段错误源码如下:



#include "openssl/bio.h"
#include "openssl/ssl.h"
#include "openssl/err.h"
void main()
{
/* Initializing OpenSSL */
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
SSL_CTX *ctx = SSL_CTX_new(SSLv23_server_method());
if(! SSL_CTX_load_verify_locations(ctx, "/NFS_mount/chip/project/openssl_test/server/Certificate/cacert.crt", NULL))
{
    printf("Handle failed load here!\n");
}
}

makefile如下:
downCA: downCA.c
        gcc downCA.c -lssl -o downCA
clean:
        rm  downCA



[root@localhost server]# make
gcc downCA.c -lssl -o downCA
downCA.c: 在函数 ‘main’ 中:
downCA.c:4: 警告:‘main’ 的返回类型不是 ‘int’
警告但没报错运行downCA
./downCA
[root@localhost server]# ./downCA
段错误


有经验的兄弟帮帮忙阿~
 楼主| 发表于 2007-7-26 18:42:28 | 显示全部楼层
参考了http://www.ibm.com/developerworks/cn/linux/l-openssl.html的作者的handshake.c(http://www.kennethballard.com/developerWorks/sslhandshake.c)源码一样编译没问题,但是运行的时候出错,怀疑我的架构和内核了
回复

使用道具 举报

 楼主| 发表于 2007-7-26 18:55:30 | 显示全部楼层
通过修改makefile:

downCA: downCA.c
        gcc downCA.c -lssl -static -o downCA
clean:
        rm  downCA

出现了一大堆错误:
(.text+0x19f1): undefined reference to `ERR_put_error'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_srvr.o): In function `ssl2_accept':
(.text+0x19fb): undefined reference to `ERR_clear_error'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_srvr.o): In function `ssl2_accept':
(.text+0x1a3e): undefined reference to `ERR_put_error'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_srvr.o): In function `ssl2_accept':
(.text+0x1a76): undefined reference to `ERR_put_error'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_srvr.o): In function `ssl2_accept':
(.text+0x1abe): undefined reference to `ERR_put_error'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_srvr.o): In function `ssl2_accept':
(.text+0x1b10): undefined reference to `ERR_put_error'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_srvr.o): In function `ssl2_accept':
(.text+0x1b5f): undefined reference to `ERR_put_error'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_srvr.o).text+0x1ba7): more undefined references to `ERR_put_error' follow
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_lib.o): In function `ssl2_write_error':
(.text+0x1ed): undefined reference to `OpenSSLDie'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_lib.o): In function `ssl2_generate_key_material':
(.text+0x25c): undefined reference to `EVP_md5'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_lib.o): In function `ssl2_generate_key_material':
(.text+0x267): undefined reference to `EVP_MD_CTX_init'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_lib.o): In function `ssl2_generate_key_material':
(.text+0x2c6): undefined reference to `EVP_DigestUpdate'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_lib.o): In function `ssl2_generate_key_material':
(.text+0x2dd): undefined reference to `EVP_DigestUpdate'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_lib.o): In function `ssl2_generate_key_material':
(.text+0x2fd): undefined reference to `EVP_DigestUpdate'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(s2_lib.o): In function `ssl2_generate_key_material':


这是否说明是库本身的问题?libssl.so?libssl.a

[ 本帖最后由 ruger 于 2007-7-26 18:58 编辑 ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-25 01:25 , Processed in 0.057430 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表