ruger 发表于 2007-7-26 18:29:19

openssl编程,出错

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:
      rmdownCA



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


有经验的兄弟帮帮忙阿~

ruger 发表于 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)源码一样编译没问题,但是运行的时候出错,怀疑我的架构和内核了

ruger 发表于 2007-7-26 18:55:30

通过修改makefile:

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

出现了一大堆错误:
(.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 编辑 ]
页: [1]
查看完整版本: openssl编程,出错